SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
Peça seu código
                                    em casamento:
                                    TDD do jeito certo!
                                    @rafaelcaricio




quinta-feira, 30 de junho de 2011
Quem sou eu?

                                    @rafaelcaricio



quinta-feira, 30 de junho de 2011
Quando você ama e confia...




quinta-feira, 30 de junho de 2011
pede em casamento...




quinta-feira, 30 de junho de 2011
Não vou ensinar a consseguir
                                     uma noiva (ou namorada)...




quinta-feira, 30 de junho de 2011
Como confiar e amar seu código
                                   e assim casar com ele...




                                      TDD, Votos e Tópicos

quinta-feira, 30 de junho de 2011
Qual o problema?


                                    Dificio manutenção
                                     Código obscuro
                                           Bugs
                                            ...


quinta-feira, 30 de junho de 2011
O que é Test Driven Development?




quinta-feira, 30 de junho de 2011
O que é Test Driven Development?




quinta-feira, 30 de junho de 2011
Fluxo de desenvolvimento

                                                    Design



                                    Test                         Test



                                                  Implement




quinta-feira, 30 de junho de 2011
O que é um teste?

                                    Um bloco de código que descreve um
                                        comportamento desejado. *




quinta-feira, 30 de junho de 2011
Exemplo

                              from friends import Tarsis

                              def test_falar_bonito():
                                  tarsisazevedo = Tarsis()
                                  palavras = tarsisazevedo.fala(2)
                                  assert 2 == len(palavras)




quinta-feira, 30 de junho de 2011
Exemplo

                              from friends import Tarsis

                              def test_falar_bonito():
                                  tarsisazevedo = Tarsis()
                                  palavras = tarsisazevedo.fala(2)
                                  assert 2 == len(palavras)




          O que você espera que vai
                 acontecer!
quinta-feira, 30 de junho de 2011
TDD não garante o melhor código!

                              def fala(o):
                                  c = None
                                  return [“foco”] * o

                              class Tarsis():

                                    def __init__(self, *args, **kwargs):
                                        pass

                                    def fala(self, o):
                                        print “aqui: ” + str(o)
                                        a = fala(o)
                                        return a




quinta-feira, 30 de junho de 2011
Faça refactory
                                    do seu código!




quinta-feira, 30 de junho de 2011
class Tarsis():

                             def fala(self, numero_palavras):
                                 return [“foco”] * numero_palavras




quinta-feira, 30 de junho de 2011
class Tarsis():

                             def fala(self, numero_palavras):
                                 return [“foco”] * numero_palavras




quinta-feira, 30 de junho de 2011
class Tarsis():

                             def fala(self, numero_palavras):
                                 return [“foco”] * numero_palavras




quinta-feira, 30 de junho de 2011
O que eu posso usar para
                                 testar meu código?

                                     - unittest
                                     - Nose
                                     - pytest
                                     - pyVows


quinta-feira, 30 de junho de 2011
Vamos a um exemplo...


                     def test_sum_returns_42():
                         result = add_two_numbers(41, 1)

                         assert result
                         assert int(result)
                         assert result == 42




quinta-feira, 30 de junho de 2011
Uma forma mais organizada...


                                    def test_sum_returns_result():
                                        result = add_two_numbers(41, 1)
                                        assert result

                                    def test_sum_returns_a_number():
                                        result = add_two_numbers(41, 1)
                                        assert int(result)

                                    def test_sum_returns_42():
                                        result = add_two_numbers(41, 1)
                                        assert result == 42




quinta-feira, 30 de junho de 2011
Alguns problemas identificados


                                    Repetição de código
                                    Muitos testes executando o mesmo
                                    código desnecessariamente

                                    Código ilegível
                                    Um teste com inúmeros asserts



quinta-feira, 30 de junho de 2011
Alguns problemas identificados


                                    Repetição de código                Tópicos
                                    Muitos testes executando o mesmo
                                    código desnecessariamente

                                    Código ilegível                    Votos
                                    Um teste com inúmeros asserts



quinta-feira, 30 de junho de 2011
Uma boa ideia ...


                             class SumContext(Vows.Context):

                                 def topic(self):
                                     return add_two_numbers(41, 1)

                                 def we_get_a_result(self, topic):
                                     expect(topic).Not.to_be_null()

                                 def we_get_a_number(self, topic):
                                     expect(topic).to_be_numeric()

                                 def we_get_42(self, topic):
                                     expect(topic).to_equal(42)

quinta-feira, 30 de junho de 2011
quinta-feira, 30 de junho de 2011
quinta-feira, 30 de junho de 2011
Um exemplo prático...




quinta-feira, 30 de junho de 2011
Xiii... mas eu não gostei desse “expect”




quinta-feira, 30 de junho de 2011
Xiii... mas eu não gostei desse “expect”


                                    Use o assert! :)




quinta-feira, 30 de junho de 2011
Xiii... mas eu não gostei desse “expect”


                                    Use o assert! :)
                               class SumContext(Vows.Context):

                                   def topic(self):
                                       return add_two_numbers(41, 1)

                                   def we_get_a_result(self, topic):
                                       assert None != topic


quinta-feira, 30 de junho de 2011
Gostei do “expect”, mas não tem
                           um que atenda minha necessidade!




quinta-feira, 30 de junho de 2011
Gostei do “expect”, mas não tem
                           um que atenda minha necessidade!

                                    Crie um! :)




quinta-feira, 30 de junho de 2011
Gostei do “expect”, mas não tem
                           um que atenda minha necessidade!

                                     Crie um! :)
                          @Vows.assertion
                          def to_be_less_than_2(topic):
                              assert topic < 2

                          class SumContext(Vows.Context):

                              def topic(self):
                                  return add_two_numbers(41, 1)

                              def we_get_a_result(self, topic):
                                  expect(topic).to_be_less_than_2()
quinta-feira, 30 de junho de 2011
Certo, mas como instalo o pyVows?




                             $ pip install pyvows




quinta-feira, 30 de junho de 2011
Extensões


                      •       Tornado
                      •       Django*
                      •       ...


quinta-feira, 30 de junho de 2011
Como contribuir?




                 •                  Pull request
         https://github.com/heynemann/pyvows/

quinta-feira, 30 de junho de 2011
Hora de jogar o buquê!




quinta-feira, 30 de junho de 2011
Peça seu código
                                    em casamento:
                                    TDD do jeito certo!




quinta-feira, 30 de junho de 2011
Dúvidas?
                                    A hora é agora!

                                       Peça seu código
                                       em casamento:
                                       TDD do jeito certo!



                                           @rafaelcaricio

                                         rafael@caricio.com




quinta-feira, 30 de junho de 2011

Mais conteúdo relacionado

Destaque

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Destaque (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Peça seu código em casamento: TDD do jeito certo!

  • 1. Peça seu código em casamento: TDD do jeito certo! @rafaelcaricio quinta-feira, 30 de junho de 2011
  • 2. Quem sou eu? @rafaelcaricio quinta-feira, 30 de junho de 2011
  • 3. Quando você ama e confia... quinta-feira, 30 de junho de 2011
  • 5. Não vou ensinar a consseguir uma noiva (ou namorada)... quinta-feira, 30 de junho de 2011
  • 6. Como confiar e amar seu código e assim casar com ele... TDD, Votos e Tópicos quinta-feira, 30 de junho de 2011
  • 7. Qual o problema? Dificio manutenção Código obscuro Bugs ... quinta-feira, 30 de junho de 2011
  • 8. O que é Test Driven Development? quinta-feira, 30 de junho de 2011
  • 9. O que é Test Driven Development? quinta-feira, 30 de junho de 2011
  • 10. Fluxo de desenvolvimento Design Test Test Implement quinta-feira, 30 de junho de 2011
  • 11. O que é um teste? Um bloco de código que descreve um comportamento desejado. * quinta-feira, 30 de junho de 2011
  • 12. Exemplo from friends import Tarsis def test_falar_bonito(): tarsisazevedo = Tarsis() palavras = tarsisazevedo.fala(2) assert 2 == len(palavras) quinta-feira, 30 de junho de 2011
  • 13. Exemplo from friends import Tarsis def test_falar_bonito(): tarsisazevedo = Tarsis() palavras = tarsisazevedo.fala(2) assert 2 == len(palavras) O que você espera que vai acontecer! quinta-feira, 30 de junho de 2011
  • 14. TDD não garante o melhor código! def fala(o): c = None return [“foco”] * o class Tarsis(): def __init__(self, *args, **kwargs): pass def fala(self, o): print “aqui: ” + str(o) a = fala(o) return a quinta-feira, 30 de junho de 2011
  • 15. Faça refactory do seu código! quinta-feira, 30 de junho de 2011
  • 16. class Tarsis(): def fala(self, numero_palavras): return [“foco”] * numero_palavras quinta-feira, 30 de junho de 2011
  • 17. class Tarsis(): def fala(self, numero_palavras): return [“foco”] * numero_palavras quinta-feira, 30 de junho de 2011
  • 18. class Tarsis(): def fala(self, numero_palavras): return [“foco”] * numero_palavras quinta-feira, 30 de junho de 2011
  • 19. O que eu posso usar para testar meu código? - unittest - Nose - pytest - pyVows quinta-feira, 30 de junho de 2011
  • 20. Vamos a um exemplo... def test_sum_returns_42():     result = add_two_numbers(41, 1)     assert result     assert int(result)     assert result == 42 quinta-feira, 30 de junho de 2011
  • 21. Uma forma mais organizada... def test_sum_returns_result():     result = add_two_numbers(41, 1)     assert result def test_sum_returns_a_number():     result = add_two_numbers(41, 1)     assert int(result) def test_sum_returns_42():     result = add_two_numbers(41, 1)     assert result == 42 quinta-feira, 30 de junho de 2011
  • 22. Alguns problemas identificados Repetição de código Muitos testes executando o mesmo código desnecessariamente Código ilegível Um teste com inúmeros asserts quinta-feira, 30 de junho de 2011
  • 23. Alguns problemas identificados Repetição de código Tópicos Muitos testes executando o mesmo código desnecessariamente Código ilegível Votos Um teste com inúmeros asserts quinta-feira, 30 de junho de 2011
  • 24. Uma boa ideia ... class SumContext(Vows.Context):     def topic(self):         return add_two_numbers(41, 1)     def we_get_a_result(self, topic):         expect(topic).Not.to_be_null()     def we_get_a_number(self, topic):         expect(topic).to_be_numeric()     def we_get_42(self, topic):         expect(topic).to_equal(42) quinta-feira, 30 de junho de 2011
  • 25. quinta-feira, 30 de junho de 2011
  • 26. quinta-feira, 30 de junho de 2011
  • 28. Xiii... mas eu não gostei desse “expect” quinta-feira, 30 de junho de 2011
  • 29. Xiii... mas eu não gostei desse “expect” Use o assert! :) quinta-feira, 30 de junho de 2011
  • 30. Xiii... mas eu não gostei desse “expect” Use o assert! :) class SumContext(Vows.Context):     def topic(self):         return add_two_numbers(41, 1)     def we_get_a_result(self, topic):         assert None != topic quinta-feira, 30 de junho de 2011
  • 31. Gostei do “expect”, mas não tem um que atenda minha necessidade! quinta-feira, 30 de junho de 2011
  • 32. Gostei do “expect”, mas não tem um que atenda minha necessidade! Crie um! :) quinta-feira, 30 de junho de 2011
  • 33. Gostei do “expect”, mas não tem um que atenda minha necessidade! Crie um! :) @Vows.assertion def to_be_less_than_2(topic): assert topic < 2 class SumContext(Vows.Context):     def topic(self):         return add_two_numbers(41, 1)     def we_get_a_result(self, topic):         expect(topic).to_be_less_than_2() quinta-feira, 30 de junho de 2011
  • 34. Certo, mas como instalo o pyVows? $ pip install pyvows quinta-feira, 30 de junho de 2011
  • 35. Extensões • Tornado • Django* • ... quinta-feira, 30 de junho de 2011
  • 36. Como contribuir? • Pull request https://github.com/heynemann/pyvows/ quinta-feira, 30 de junho de 2011
  • 37. Hora de jogar o buquê! quinta-feira, 30 de junho de 2011
  • 38. Peça seu código em casamento: TDD do jeito certo! quinta-feira, 30 de junho de 2011
  • 39. Dúvidas? A hora é agora! Peça seu código em casamento: TDD do jeito certo! @rafaelcaricio rafael@caricio.com quinta-feira, 30 de junho de 2011