4.5. Split personality
One of the easiest ways to improve your tests is to look for a condition I call split personality. When a test exhibits split personality, it thinks it embodies multiple tests in itself. That’s not right. A test should only check one thing and check it well.[4]
4 Note that this is different from the “one assertion per test” guideline that you may have bumped into—you might use multiple assertions to check that one thing!
Time for an example again.
4.5.1. Example
The test class in the next listing is for a piece of command-line interface. Essentially, it’s testing the behavior of a Configuration object with different command-line arguments. Let’s take a look.
Listing 4.13. Test for parsing command-line arguments
public ...
Get Effective Unit Testing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.