FC ConcursosFC Concursos

Questão FC586510

Set the Table When you begin writing tests, you will discover a common pattern: 1. Create some objects 2. Stimulate them 3. Check the results While the stimulation and checking ste

Questões Interdisciplinares de Inglês

Instituto AOCP · 2018

Set the Table

When you begin writing tests, you will discover a common pattern:

1. Create some objects

2. Stimulate them

3. Check the results

While the stimulation and checking steps are unique test-to-test, the creation step is often familiar. I have a 2 and 3. If I add them, I expect 5. If I subtract them, I expect – 1, if I multiply them, I expect 6. The stimulation and expected results are unique, the 2 and the 3 don’t change.

If this pattern repeats at different scales (and it does), then we’re faced with the question of how often do we want to create new objects. Looking back at our initial set of constraints, two constraints come into conflict:

· Performance—we would like our tests to run as quickly as possible · Isolation—we would the success or failure of one test to be irrelevant to other tests

For performance sake, assuming creating the objects (we’ll call them collectively the “fixture”) is expensive, we would like to create them once and then run lots of tests.

But sharing objects between tests creates the possibility of test coupling. Test coupling can have an obvious nasty effect, where breaking one test causes the next ten to fail even though the code is correct. Test coupling can have a subtle really nasty effect, where the order of tests matters. If I run A before B, they both work, but if I run B before A, then A fails. Worse, the code exercised by B is wrong, but because A ran first, the test passes.

Kent Beck – Test-Driven Development By Example. Addison-Wesley Professional; Edição: 1. Novembro, 2002. Page 82.

Based on the text it is correct to state about the coupling of tests that:

  1. During the coupling of tests, breaking one test may not affect other tests since the code is correct.
  2. In the test coupling, two constraints can conflict such as the creation of objects and the performance.
  3. The coupling must be performed in isolation so that it does not have an unpleasant effect.
  4. Performance is highly impaired when coupling the tests.
  5. In the coupling of tests, the order of the tests is important.
Mostrar resposta e comentário

Gabarito

Errado

Comentário do professor

A afirmativa está correta: no contexto do acoplamento de testes, a ordem de execução importa porque testes que compartilham o mesmo conjunto de objetos ou estado podem influenciar uns aos outros.

Quando a criação da fixture é feita uma única vez por questão de desempenho, qualquer alteração no estado compartilhado por um teste pode afetar o seguinte. Assim, é possível que executar A antes de B resulte em sucesso, enquanto executar B antes de A cause falha, configurando uma dependência temporal entre testes.

Esse comportamento gera testes instáveis, falhas em cascata e dificuldade na identificação de bugs. Para prevenir, recomenda-se garantir isolamento: usar fixtures imutáveis, recriar objetos por teste ou limpar o estado em rotinas de setup/teardown.

Conteúdo do catálogo FC Concursos · Atualizado em

Continue aprendendo