*Updated* 4 November 2010: Added another reason for writing tests: Documentation
Reasons why you should write *tests* in the first place
- You get a bug report and want to proof when the bug is fixed
This is a good practice before fixing bugs
- You implement a new feature and write a test beforehand to see when the new feature is done
- You want prevent regression
Changes in your code will break other code. So you have a test around it to know if everything is still green (=OK)
As an agile developer you change code all the time, either because
- You do TDD
- You follow the Boy scout rule (Leave the campground cleaner than you found it) and refactor your code
- Your client/customer changes his mind (which is even more likely)
- Documentation goes out of date sooner or later. Tests document how the system works and additionally they are executable
Why don't you write tests?
Note about “documentation” vs. “tests”
- Documentation normally describes what the system should or might do
- Tests describe and make sure what the system does do
Reasons for automated tests
Automating means, those tests run on certain events on a certain machine. Typically on a build server on check in. Continuous integration follows this practice. More details on Continuous Integration in Martin Fowlers article
- Faster feedback
If you have an automated test, everyone can immediately see if the latest code change, broke something
- Saves time
Testing can be very boring, because it is repetitive and needs to be done very often during the day. Automated tests can take off this work from us, so we don't need to test the system ourselves. Humans are slow
- Safety net for code changes
Because of this fast feedback that we get from tests, we are not afraid to change our code. Although we should "Never change a running system", with tests we can easily verify if our change broke something
- Testers are humans, and humans make mistakes
A tester will decide what to test, and what not. He will maybe make mistakes during testing. All these problems can be prevented with automated tests
Why don't you automate your tests?
Problems with automating tests.
How to prevent people saying: it's too difficult, It takes too long, Its not my job.