3. Notable Software Failures
Ariane 5
An overflow happened
during the conversion from
a 64-bit float to a 16-bit
signed integer, causing a
processor trap.
4. Improving Software Quality
Software Quality: "capability of a software
product to conform to requirements" (ISO/IEC
9001)
How can we write software that better
conforms to requirements?
6. Test Driven Development
Requirements are written before
implementation, using tests (unit/integration)
Production code is only written to make the
tests pass - in other words, only to satisfy
requirements!
If there's not a requirement (hence a test)...
You Ain't Gonna Need It!
7. TDD Cycle
RED: write a test for a
requirement that has not
been implemented yet...
GREEN: write the minimum
code to make the test
pass...
REFACTOR: do not repeat
yourself, extract methods,
remove code smells... tidy
up the camp!
8. TDD Rules
● No production code can be written without
a test
● The test should ALWAYS fail before starting
to write code
● Drive objects and methods creation from
the test, using your IDE
● Do the minimum required to have your
current test pass without breaking the
previous
● Never skip refactor phase!!!
9. TDD Best Practices
● Write your asserts first
● Outside-In approach
● Never refactor on a failing test
● Write Class Responsibility Collaboration
cards in advance
● Drive collaborators development by testing
interactions with the current class
10. TDD Benefits
● Testable code
● High coverage (but coverage is not a
goal...)
● Nothing more than what needed is
delivered (no surprises)
● Clean code (provided refactoring is never
skipped)
● Productivity improves with time -
developers have trust in changing the code
(new features and maintenance)
11. TDD Myths (aka Disclaimer)
● TDD immediately gives you all the benefits
○ The learning curve is steep, but in the mid-term
pays off with higher productivity and less defects.
○ Should be gradually introduced and practiced
● TDD gives you 100% bug-free code
○ Drastically reduces the bug rate but...
Program testing could show the presence of bugs,
never their absence!
E. Dijkstra