6.7. Conditional tests

Modern programming languages are amazing. Over the years we’ve seen languages evolve and APIs expand. Among other things, we’ve seen language constructs make their way from libraries into the core language. But more power isn’t good when it’s used wrongly, and the conditional test smell is a case in point.

A conditional test is one that’s hiding a secret conditional within a test method, making the test logic different from what its name would suggest. Our previous test smell, platform prejudice, featured an example of one specific type of conditional test, but let’s make the case for conditional tests in our tests being bad in general, and we’ll do that with an example.

6.7.1. Example

The next listing presents a test that ...

Get Effective Unit Testing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.