Sunday, 8 May 2011

Unit Tests and the FIRST Acronym

ObjectMentor came up with a really good acronym to describe Unit test, it’s FIRST and it describes all the qualities of a good test.

F - Fast. Tests should be fast, if your tests are slow, then they won’t get run frequently enough and if they don’t get run frequently problems will not be found and code will not be refactored when necessary.

I - Independent. Test should be independent, meaning that you should be able to run them in any order. One test failing such not cause other downstream tests to fail.

R - Repeatable. Test be repeatable in any environment: dev, test etc.

S - Self Validating. Tests should be self-validating, meaning that they should pass or fail and not require any intervention on the part of a developer, tester etc. (for example looking through a log).

T - Timely. See TDD. Tests should be written just before the production code.

See Page 132 of Bob Martin’s Clean Code where this is described.

No comments: