3. 3 Laws of TDD
• First Law: You may not write production code
until you have written a failing unit test.
• Second Law: You may not write more of a
unit test than is sufficient to fail, and not
compiling
• Third Law: You may not write more
production code than is sufficient to pass the
currently
Clean Code, p122 ; Robert Martin
6. “As the tests get more specific, the code gets
more generic.”
- Uncle Bob
7. Refactoring
• Change code without changing its behavior
• Refactoring != Redesign
• Remove the Fake
• Remove Duplication
• Refactor both test code and production code
8. F.I.R.S.T. Unit Tests
• Fast
• Independent
• Repeatable
• Self-validating
• Timely
Clean Code, pp 132-133 ; Robert Martin
9. Test Methods
• Single assert
• No conditional logic
• Standard format
– Setup
– Exercise
– Verify
– Teardown
11. Let’s Start!
• Kata: StringCalculator
• Test method Example
add_With_Empty_String_Returns_Zero()
Notes de l'éditeur
Arrange all the things needed to exercise the code
Act on the code you want to verify
Assert that the code worked as expected
Robert Martin
“uncle bob”
OO design guru - S.O.L.I.D. principles
One of 17 formulator’s of Agile manifesto.
Manifesto his idea
One founder of “Craftsmanship” movement. Manifesto for Software Craftsmanship.
Fast
Must be able to run quickly. <10 minutes ideal
Independent
No test should depend on another. Order should not matter.
Repeatable
Should be able to run them at any stage, development, QA, production
Timely
- Created with code
Having a single assert is an ideal. The idea is that the test should test ONLY ONE THING. In practice you might find a couple of asserts are needed, but try to keep it to one.