Workshop:�Test Driven Development
Lorenzo Spinelli
Tiziano Pessa
What are we going to do?
Brief intro: TDD - What, How & Why?
Hands on session - let’s code together
TDD_
What
How
Why?
image credit: Adobe stock
Production failures
Study of 198 production failures
(Paper)
https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf
58%
Easily avoided with adequate test coverage
We need a powerful error detection protocol
it’s about ensuring that when we push code into production
we do so with the confidence that it won’t break anything.
It's not about admitting that we’re not good developers;
Testing
Testing (verb)
Evaluating a system, product, or software to assess its functionality, performance, reliability, and quality
by executing it under specific conditions to identify defects and ensure it meets requirements
The "No time for testing" death spiral
Stress
Less test
Automated tests
The Test Pyramid
https://martinfowler.com/articles/practical-test-pyramid.html
BDD
TDD
What is TDD?
Writing tests before writing the code
Writing code only to pass the tests
TDD is about expressing intent
The TDD process
1. Write a Test
2. Run the Test
Repeat
Red phase
Green phase
Gray phase
3. Write the Code
4. Run the Test Again
5. Refactor
Two simple rules
TDD phases
Write a little test that doesn't work
Red phase
Green phase
Gray phase
Make the test work quickly
Eliminate duplication
Key benefits of TDD
The attributes of good code
The attributes of good code
The attributes of testable code
TDD: the talent amplifier
Testing is not a magic fix!
It won't instantly make you the best programmer in the world.
Bad programmer
Less bad programmer
Good programmer
Better programmer
Great programmer
Greater programmer
Any questions so far?
TDD_
Let’s code!
Goal
Supplier | Quantity | Price | Total |
CodeCorp | 1000 | 25 USD | 25000 USD |
BugBusters | 400 | 150 CHF | 60000 CHF |
| | | |
Total | | | 65000 USD |
From | To | Rate |
CHF | USD | 1.5 |
https://github.com/firenzedev/tdd-workshop
We want to drive the development with automated tests