Tests
Why Testing is Important
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
Goal
- why tests are important?
- what are their advantages?
- what are the techniques to write good tests?
Pros
- Finding problems
- Understanding code
- Increase trust
Finding Problems: Pros
- find bugs when they appear
- improve customer trust
- reproduce complex scenari
- check contracts of super types
- guarantee old bugs won't come back
- isolate the problem
Finding Problems: Characteristics of a Good Test Suite
- check extreme cases (e.g., null, 0 and empty)
- check complex cases (e.g., exceptions, network pbs)
- 1 test for each bug (at least)
- good coverage
- check abstractions
- check units independently
Understanding Code
Understanding Code
Understanding Code
Understanding Code
Understanding Code: Pros
- give simple and reproducible examples
- explain an API
- give up-to-date documentation
- check conformity of new code
- offer a first client to new code
- force a modular design
Understanding Code: Characteristics of a Good Test Suite
- deterministic
- automatic
- self-explained
- simple
- unit
Increasing Trust: Pros
- accelerate bug detection
- accelerate new code checking
- ease refactorings
- prevent regressions
Increasing Trust: Characteristics of a Good Test Suite
- change less frequently than the rest
- good code coverage
- deterministic
Collateral Pros
- improve feeling of customers who care
- allow for automatic bug fixing
- improve type inference
- provide examples to variable values
Testing Abstractions
How do you test contracts of abstract types?
Testing Abstractions
How do you test that one and only one state is active at any time?
Testing Abstractions
Testing Abstractions
- parallel hierarchies
- test must be in the highest abstraction
- factory method
Mocking
How do you test that a questionnaire only accepts compatible answers from the user?
Mocking
How do you test that a questionnaire only accepts compatible answers from the user?
Mocking
Mocking
- mocks are reusable across tests
- mocks can be generated with mocking frameworks
/