SlideShare ist ein Scribd-Unternehmen logo
1 von 36
TDD
UNIT TESTING DONE RIGHT
AND PROGRAMMER HAPPINESS
Nov 2018
Erez Cohen
Why would you want to hear about
Test Driven Development?
I heard about TDD long ago, but in the past year I really put
it to the Test ;)
I discovered that developing using TDD is more rewarding
and more fun then writing the tests after writing the
production code.
You create better code while enjoying the process…
WHY UNIT TEST?
☛ Safer refactoring
☛ Easier to check complex functionality
☛ Faster on feedback
☛ Faster to fix
☛ More stable
☛ Easier to write and run / setup
Compared to E2E / Integration tests, Unit
tests are:
Note that unit tests
cannot replace
integration and
E2E tests!
THEY COMPLETE EACH OTHER
WHY TDD?
What happens when you write the tests
AFTER writing the production code?
No Fun
(you already
know it works)
Quality
Suffers
(We can only do 1 thing well at a time)
Hard to cover
everything
→ Harder to refactor
→ Code “rots”
→ Slows down everyone
THE RESULT:
Eventually, the tests suit is full of holes…
→ Are we really green?
(When the suit passes, are we good to deploy?)
What happens when you write the test
BEFORE writing the production code?
☛ Better quality: less coupling, less spaghetti.
☛ Better coverage.
☛ At any point: Everything worked a minute ago. Means
less debugging.
☛ Order and focus. Next task apparent.
☛ Documentation of the best kind: usage example. And
Always synced.
😁 Fun: Quick feedback on turning a test green
→ Safer to refactor
→ code doesn’t “rot”
→ Eventually Faster
THE RESULT:
→ Green means green!
The Three Laws of TDD - Bob Martin (Uncle Bob)
https://www.youtube.com/watch?v=qkblc5WRn-U
Objection!
TDD is dead, long live testing – David Heinemeier Hansson (DHH)
http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html
Why Most Unit Testing is Waste by - James Coplien
https://rbcs-us.com/documents/Why-Most-Unit-Testing-is-Waste.pdf
⇣ Longer dev time
⇣ Tests keep breaking on refactor
⇣ Too much mocking
⇣ Bottom-up architecture
⇣ Used where not applicable
Jim Coplien And Bob Martin Debate TDD
https://www.youtube.com/watch?v=KtHQGs3zFAM
Is TDD Dead? - Martin Fowler, Kent Beck And DHH
https://plus.google.com/events/ci2g23mk0lh9too9bgbp3rbut0k
Why do people object to TDD?
When in doubt go back
to the source…
In our case it is
Test-Driven Development by Example
(Kent Beck ,2000)
How to
Unit Test
CORRECTLY?
☛ Test the API of the MODULE
The “Export”/”Facade”. (not necessarily a class)
☛ Don't test the implementation *
☛ Minimize mocks usage
☛ Tests should be independent of each other
The exceptions: complex data manipulation, calculations…
*
What should be the trigger to add a test?
It's not "I need to add a new method"
It's "I need to IMPLEMENT A REQUIREMENT"
TDD, Where Did It All Go Wrong – Ian Cooper
https://www.youtube.com/watch?v=EZ05e7EMOLM
AVOID TESTING IMPLEMENTATION DETAILS,
TEST BEHAVIORS
Ports and Adapters Architecture
Unit test
on these!
TDD No TDD
TDD implementation: +15 ~ 30% dev time
Bugs reduced: 40% - 80%
Time for fixing a bug in prod vs dev: up to 15x more
The Outrageous Cost of Skipping TDD & Code Reviews - Eric Elliott
https://medium.com/javascript-scene/the-outrageous-cost-of-skipping-tdd-code-reviews-57887064c412
What do the Researches say?
Example:
Assume 1000 hours project, 60% bugs reduced using TDD
Result: WITH TDD => 623 HOURS SAVED!
https://medium.com/javascript-scene/the-outrageous-cost-of-skipping-tdd-code-reviews-57887064c412
☛ Start off simple
☛ Keep unit tests small and fast
☛ Check one thing only in a test
Some more unit tests best practices: :
And more:
Unit Testing Guidelines https://petroware.no/unittesting.html
TDD IN PRACTICE
RED: See the test fail! (Avoid false positives).
GREEN: Make it pass. Quick and dirty.
REFACTOR (optional):
Make the code clean, remove code smells, apply patterns.
Uncle Bob's Three Rules of TDD
1. You are not allowed to write any production code unless it is to
make a failing unit test pass.
2. You are not allowed to write any more of a unit test than is
sufficient to fail; and compilation failures are failures.
3. You are not allowed to write any more production code than is
sufficient to pass the one failing unit test.
TheThreeRulesOfTdd – Uncle Bob
http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
Uncle Bob's Three Rules of TDD => REFACTORED
1. Write only enough of a unit test to fail.
2. Write only enough production code to
make the failing unit test pass.
Detailed here:
http://www.javiersaldana.com/tech/2014/11/26/refactoring-the-three-laws-of-tdd.html
DEMO
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
brian d foy
 
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
Steve Lange
 
Auditing Drupal Sites
Auditing Drupal SitesAuditing Drupal Sites
Auditing Drupal Sites
Exove
 
Agile testing for mere mortals
Agile testing for mere mortalsAgile testing for mere mortals
Agile testing for mere mortals
Dave Haeffner
 
Reliable tests with selenium web driver
Reliable tests with selenium web driverReliable tests with selenium web driver
Reliable tests with selenium web driver
PawelPabich
 
Django strategy-test
Django strategy-testDjango strategy-test
Django strategy-test
Royce Haynes
 

Was ist angesagt? (20)

Essential tdd lesson-brief-intro-tdd
Essential tdd lesson-brief-intro-tddEssential tdd lesson-brief-intro-tdd
Essential tdd lesson-brief-intro-tdd
 
Agile Testers: Becoming a key asset for your team
Agile Testers: Becoming a key asset for your teamAgile Testers: Becoming a key asset for your team
Agile Testers: Becoming a key asset for your team
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?
 
Selenium Users Anonymous
Selenium Users AnonymousSelenium Users Anonymous
Selenium Users Anonymous
 
How to Deliver the Right Software (Specification by example)
How to Deliver the Right Software (Specification by example)How to Deliver the Right Software (Specification by example)
How to Deliver the Right Software (Specification by example)
 
Hindsight lessons about API testing
Hindsight lessons about API testingHindsight lessons about API testing
Hindsight lessons about API testing
 
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
 
TDD - Test Driven Dvelopment | Test First Design
TDD -  Test Driven Dvelopment | Test First DesignTDD -  Test Driven Dvelopment | Test First Design
TDD - Test Driven Dvelopment | Test First Design
 
How to Build and Maintain Quality Drupal Sites with Automated Testing
How to Build and Maintain Quality Drupal Sites with Automated TestingHow to Build and Maintain Quality Drupal Sites with Automated Testing
How to Build and Maintain Quality Drupal Sites with Automated Testing
 
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Cje demo
Cje demoCje demo
Cje demo
 
Auditing Drupal Sites
Auditing Drupal SitesAuditing Drupal Sites
Auditing Drupal Sites
 
Agile testing for mere mortals
Agile testing for mere mortalsAgile testing for mere mortals
Agile testing for mere mortals
 
Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal SiteFive Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal Site
 
Level Up Your Automated Tests
Level Up Your Automated TestsLevel Up Your Automated Tests
Level Up Your Automated Tests
 
Reliable tests with selenium web driver
Reliable tests with selenium web driverReliable tests with selenium web driver
Reliable tests with selenium web driver
 
Test automation – the bitter truth
Test automation – the bitter truthTest automation – the bitter truth
Test automation – the bitter truth
 
Agille Testing Meetup 1
Agille Testing Meetup 1Agille Testing Meetup 1
Agille Testing Meetup 1
 
Django strategy-test
Django strategy-testDjango strategy-test
Django strategy-test
 

Ähnlich wie TDD - Unit testing done right and programmer happiness

Cf objective2014 testing-testingeverywhere
Cf objective2014   testing-testingeverywhereCf objective2014   testing-testingeverywhere
Cf objective2014 testing-testingeverywhere
ColdFusionConference
 

Ähnlich wie TDD - Unit testing done right and programmer happiness (20)

TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
Bdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propriBdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propri
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
Cf objective2014 testing-testingeverywhere
Cf objective2014   testing-testingeverywhereCf objective2014   testing-testingeverywhere
Cf objective2014 testing-testingeverywhere
 
Cf objective2014 testing-testingeverywhere
Cf objective2014   testing-testingeverywhereCf objective2014   testing-testingeverywhere
Cf objective2014 testing-testingeverywhere
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
That worked before
That worked beforeThat worked before
That worked before
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzieHey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 

Kürzlich hochgeladen

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Kürzlich hochgeladen (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

TDD - Unit testing done right and programmer happiness

  • 1. TDD UNIT TESTING DONE RIGHT AND PROGRAMMER HAPPINESS Nov 2018 Erez Cohen
  • 2. Why would you want to hear about Test Driven Development?
  • 3. I heard about TDD long ago, but in the past year I really put it to the Test ;) I discovered that developing using TDD is more rewarding and more fun then writing the tests after writing the production code. You create better code while enjoying the process…
  • 5. ☛ Safer refactoring ☛ Easier to check complex functionality ☛ Faster on feedback ☛ Faster to fix ☛ More stable ☛ Easier to write and run / setup Compared to E2E / Integration tests, Unit tests are:
  • 6. Note that unit tests cannot replace integration and E2E tests! THEY COMPLETE EACH OTHER
  • 8. What happens when you write the tests AFTER writing the production code?
  • 10. Quality Suffers (We can only do 1 thing well at a time)
  • 12. → Harder to refactor → Code “rots” → Slows down everyone THE RESULT: Eventually, the tests suit is full of holes…
  • 13. → Are we really green? (When the suit passes, are we good to deploy?)
  • 14. What happens when you write the test BEFORE writing the production code?
  • 15. ☛ Better quality: less coupling, less spaghetti. ☛ Better coverage. ☛ At any point: Everything worked a minute ago. Means less debugging. ☛ Order and focus. Next task apparent. ☛ Documentation of the best kind: usage example. And Always synced. 😁 Fun: Quick feedback on turning a test green
  • 16. → Safer to refactor → code doesn’t “rot” → Eventually Faster THE RESULT: → Green means green! The Three Laws of TDD - Bob Martin (Uncle Bob) https://www.youtube.com/watch?v=qkblc5WRn-U
  • 18. TDD is dead, long live testing – David Heinemeier Hansson (DHH) http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html Why Most Unit Testing is Waste by - James Coplien https://rbcs-us.com/documents/Why-Most-Unit-Testing-is-Waste.pdf
  • 19. ⇣ Longer dev time ⇣ Tests keep breaking on refactor ⇣ Too much mocking ⇣ Bottom-up architecture ⇣ Used where not applicable Jim Coplien And Bob Martin Debate TDD https://www.youtube.com/watch?v=KtHQGs3zFAM Is TDD Dead? - Martin Fowler, Kent Beck And DHH https://plus.google.com/events/ci2g23mk0lh9too9bgbp3rbut0k Why do people object to TDD?
  • 20. When in doubt go back to the source…
  • 21. In our case it is Test-Driven Development by Example (Kent Beck ,2000)
  • 23. ☛ Test the API of the MODULE The “Export”/”Facade”. (not necessarily a class) ☛ Don't test the implementation * ☛ Minimize mocks usage ☛ Tests should be independent of each other The exceptions: complex data manipulation, calculations… *
  • 24. What should be the trigger to add a test? It's not "I need to add a new method" It's "I need to IMPLEMENT A REQUIREMENT" TDD, Where Did It All Go Wrong – Ian Cooper https://www.youtube.com/watch?v=EZ05e7EMOLM
  • 25. AVOID TESTING IMPLEMENTATION DETAILS, TEST BEHAVIORS
  • 26. Ports and Adapters Architecture Unit test on these!
  • 28. TDD implementation: +15 ~ 30% dev time Bugs reduced: 40% - 80% Time for fixing a bug in prod vs dev: up to 15x more The Outrageous Cost of Skipping TDD & Code Reviews - Eric Elliott https://medium.com/javascript-scene/the-outrageous-cost-of-skipping-tdd-code-reviews-57887064c412 What do the Researches say?
  • 29. Example: Assume 1000 hours project, 60% bugs reduced using TDD Result: WITH TDD => 623 HOURS SAVED! https://medium.com/javascript-scene/the-outrageous-cost-of-skipping-tdd-code-reviews-57887064c412
  • 30. ☛ Start off simple ☛ Keep unit tests small and fast ☛ Check one thing only in a test Some more unit tests best practices: : And more: Unit Testing Guidelines https://petroware.no/unittesting.html
  • 32. RED: See the test fail! (Avoid false positives). GREEN: Make it pass. Quick and dirty. REFACTOR (optional): Make the code clean, remove code smells, apply patterns.
  • 33. Uncle Bob's Three Rules of TDD 1. You are not allowed to write any production code unless it is to make a failing unit test pass. 2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. 3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test. TheThreeRulesOfTdd – Uncle Bob http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
  • 34. Uncle Bob's Three Rules of TDD => REFACTORED 1. Write only enough of a unit test to fail. 2. Write only enough production code to make the failing unit test pass. Detailed here: http://www.javiersaldana.com/tech/2014/11/26/refactoring-the-three-laws-of-tdd.html
  • 35. DEMO