FIRST Properties of Unit Tests – The Code
Agile
in a Flash by Jeff Langr and Tim Ottinger (card #45)
> Fast
> Isolated
> Repeatable
> Self-verifying
> Timely
--
Fast. Tests should
be really fast. If the entire unit test suite takes a minute, people will be
reluctant to run it. Break dependencies to make tests profoundly fast and
small.
Isolated. When a test
fails, it should be for a single, obvious reason. A long, complex test may fail
in many places for many reasons. Isolated tests can run alone or in a suite, in
any order.
Repeatable. Tests can be
run in a loop, without intervention. They will continue to fail or succeed
until code is changed that breaks them. They do not leave the system in a state
that will not allow them to run again.
Self-verifying. Unit tests are
pass/fail. No interpretation is needed to determine success. If the test fails,
it states why it failed.
Timely. Unit tests are
written with the code, not after the code is completed. In TDD style, tests are
written first. Your best results will always come from following the
Red/Green/Refactor cycle.
Source: Brett Shuchert,
TimOttinger
Avoid this: “I don’t have time to write tests
because I am too busy debugging”
Another great blog article on this:
http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/
No comments:
Post a Comment