2. WHY DO WE WRITE TESTS?
• To find bugs?
• To support future refactoring and change without
regression?
• To document the system for future generations?
• Nope. Although these are awesome side-effects.
3. WHY DO WE WRITE TESTS?
• We write tests as part of the process of designing
cohesive units of code.
• Another way, tests should prove a designed
behaviour, as you are designing it.
4. WHAT MAKES A GOOD TEST?
• Orthogonality: Test one thing
• If you can’t test one class, test a few classes that
collaborate closely
• If you can’t do that, test a cohesive system as a
whole
• Mock out dependencies. If there are lots, consider
the design.
5. WHAT MAKES A GOOD TEST?
• Readability!
• Short, readable tests
• Refactor wiring into test-specific DSL’s
• Favour code over comments
6. WHAT MAKES A GOOD TEST?
• Carefully chosen names
• Test failures should clearly show what failed
• testClientThrowsExceptionOnFailedResponse
• testClientException
• Test methods should capture subject (Client),
scenario (Failed Response) and result (Throws
Exception).
7. GUIDELINES
• MUST have a single concept per test
• MUST be short and easy to read
• MUST test behaviour, not configuration or internals
• SHOULD follow a (build .. operate .. check) structure
• SHOULD have one assert per test
• Consider this a testing framework for your tests