ALM DOs and DON’Ts – Unit test

A unit test is a runnable piece of code that verifies that another piece of code (called production code) does what it is supposed to do.

A unit test has many characteristics and one of the most important is that a single unit test must verify one and only one thing.
If a unit test specifies more than one behavior things became harder to mantain. One a tests fail it has to be easy to understand what is going wrong and which section of our production code is behaving badly.

unit-test-one-thing.png

As a best practice we make each test independent to all the others: any given behaviour should be specified in one and only one test. Otherwise if you later change that behaviour, you’ll have to change multiple tests.

 

Comments are closed.