The document discusses common mistakes in test-driven development (TDD). It presents the results of a survey of programmers that identified the most common deviations from TDD practices. The top deviations included writing complex tests, forgetting to refactor, refactoring other code while working on a test, and not implementing the simplest code to pass a test. The document concludes that while TDD is not always followed perfectly, its principles still provide benefits if applied conscientiously.
12. Test-driven development (TDD) is the craft of
producing automated tests for production code, and
using that process to drive design and programming.
For every tiny bit of functionality in the production
code, you first develop a test that specifies and
validates what the code will do. You then produce
exactly as much code as will enable that test to pass.
Then you refactor (simplify and clarify) both the
production code and the test code.
www.agilealliance.org/programs/ roadmaps/Roadmap/tdd/tdd_index.htm
Thursday, June 24, 2010
19. NÃO VER O TESTE FALHAR
Thursday, June 24, 2010
20. 50
•55% nunca esquece ou
esquece raramente de ver o
38
teste falhar;
25
•24% esquece regularmente
13
ou frequentemente;
0
Never Sometimes Frequently
•4% sempre esquece;
Rarely Regularly Always
Thursday, June 24, 2010
22. 40
•44% dos
programadores
30
experientes e 52% dos
iniciantes cometem esse
20
erro regularmente ou
frequentemente;
10
0
•1% sempre esquece.
Never Sometimes Frequently
Rarely Regularly Always
Thursday, June 24, 2010
23. REFATORAR OUTRO
TRECHO DE CÓDIGO
ENQUANTO TRABALHA
EM UM TESTE
Thursday, June 24, 2010
24. 40
•40% refatora outro trecho
de código regularmente ou
frequentemente;
30
•5% refatora o tempo
todo;
20
•6% nunca refatora;
•38% dos experientes
10 fazem isso regularmente ou
frequentemente. No
0 entendo, 44% nunca faz ou
Never Sometimes Frequently
Rarely Regularly Always faz apenas raramente.
Thursday, June 24, 2010
25. NÃO COMEÇAR PELO
TESTE MAIS SIMPLES
POSSÍVEL
Thursday, June 24, 2010
26. 50 •33% não começam pelo
teste mais simples possível
38 regularmente ou
frequentemente;
25
•2% sempre cometem o
13 erro;
0
Never Sometimes Frequently •10% nunca cometem.
Rarely Regularly Always
Thursday, June 24, 2010
28. 40 •16% rodam apenas o teste
corrente regularmente ou
frequentemente;
30
•2% cometem o erro o
tempo todo;
20
•25% nunca esquecem de
rodar a suíte inteira;
10
•Programadores experientes
cometem esse erro mais
0
Never Sometimes Frequently frequentemente do que os
Rarely Regularly Always iniciantes (21% contra 15%).
Thursday, June 24, 2010
30. 40 •50% escrevem cenários
complexos regularmente ou
30
frequentemente;
•4% escreve o tempo todo;
20
•3% nunca escreve;
10 •35% dos programadores
experientes e 53% dos iniciantes
fazem isso regularmente ou
0
Never Sometimes Frequently
frequentemente;
Rarely Regularly Always
Thursday, June 24, 2010
31. NÃO IMPLEMENTAR O
CÓDIGO MAIS SIMPLES
QUE FAÇA O TESTE
PASSAR
Thursday, June 24, 2010
32. 50
•35% dos iniciantes e
38 17% dos experientes
tendem a não
25
implementar o código
mais simples que faça o
teste passar regularmente
13
ou frequentemente;
0
Never Sometimes Frequently
Rarely Regularly Always
Thursday, June 24, 2010
34. 40
•32% usam nomes não
30
claros regularmente ou
frequentemente;
20
•1% usam nomes não claros
o tempo todo;
10
•14% nunca usam e 45%
0 nunca usa ou usa raramente.
Never Sometimes Frequently
Rarely Regularly Always
30
Thursday, June 24, 2010
35. NÃO REFATORAR
CÓDIGO DE TESTE
Thursday, June 24, 2010
36. 50
•23% não refatora o código
38 de teste regularmente ou
frequentemente;
25
•1% sempre esquece de
13
refatorar;
0 •16% nunca comete o erro;
Never Sometimes Frequently
Rarely Regularly Always
32
Thursday, June 24, 2010
37. DESVIOS MAIS COMUNS
Desvio Média/Desvio Padrão Correlação de Pearson Frequente ou sempre
Escrever testes complexos 2.58 / 1.21 -0.1 26.61%
Esquecer de refatorar 2.37 / 1.17 -0.03 19.72%
Refatorar outro trecho de
2.34 / 1.36 -0.13 23.85%
código
Não comecar pelo teste mais
2.00 / 1.28 -0.09 15.14%
simples possível
Não implementar o código mais
1.90 / 1.19 -0.24 11.01%
simples que faz o teste passar
Nomes de testes não claros 1.84 / 1.25 -0.02 11.01%
Não ver o teste falhar 1.75 / 1.35 -0.22 14.22%
Não refatorar o código de teste
1.67 / 1.19 -0.21 8.72%
Rodar apenas o teste corrente
1.40 / 1.20 -0.01 5.96%
33
Thursday, June 24, 2010
43. AONDE POSSO LER MAIS
SOBRE ISSO?
•O artigo foi publicado no 1st International Workshop on Test-
Driven Development e pode ser encontrado na biblioteca da
IEEE Digital.
•Ou através da página dedicada ao trabalho em
http://www.ime.usp.br/~aniche/tdd-survey
39
Thursday, June 24, 2010