Disclaimer
- this is an introduction to unit testing
- i won't talk about :
- example are in java
and yes, i will do some over exaggeration :)
My definition
- Unit test
a test that verify one behviour of one piece of code.
Why ?
- because it's cool !
- tests are a proof the you code does what you think it should when you wrote it
- the sooner you find problem, the cheaper you'll solve them
- confidence in your code
- testable and tested code often lead to better design
- tests tell what your code do
Quality of a unit test
- Fast
- Isolated
- Repeatable
- Self-validating
- Timely
(false) problems
Why bother with tests, it just works !
I'm in hurry, I have lot of functionnal to do. I'll write the test later.
Tests are for people who don’t know how to code !
(Bigger ?) problems
- we could have write untestable code
- we have never seen our tests fail !
- often, we build test by reverse engeeniring the code
Test First
- Think what I want to do.
- Write tests according it.
- Write code that make all the tests pass.
Enjoy.
TDD : Test Driven Developpement
Test Driven Developpement
- Write exactly one failing test
- Make it pass
- Make it clean
Repeat
Test Driven Developpement
- Red
- Green
- Refactor
That's all !