ALM Dos and Don'ts: Unit Tests
Unit testing is an important part of application lifecycle management. Here's how to write maintainable tests to ensure that your production code is running as planned.
Join the DZone community and get the full member experience.
Join For FreeDo: Write independent tests. Any given behavior should be specified in one and only one test.
Don't: Write big and monolithic tests that verify many behaviors.
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 become harder to maintain. Once a test fails, it has to be easy to understand what is going wrong and which section of our production code is behaving badly.
As a best practice, we make each test independent of all the others. Any given behavior should be specified in one and only one test. Otherwise, if you change that behavior later, you'll have to change multiple tests.
Published at DZone with permission of Michele Ferracin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments