4.1. Primitive assertions

Assertions are supposed to express an assumption or intent. They’re supposed to be statements about the behavior of the code. The problem with primitive assertions is that they don’t seem to make sense because the rationale and intent of the assertion is hidden somewhere behind seemingly meaningless words and numbers, making them difficult to understand—and to validate the assertion’s correctness.

In other words, a primitive assertion is one that uses more primitive elements than the behavior it’s checking. Let’s look at an example that exhibits this smell.

4.1.1. Example

Our example, shown in listing 4.1, presents a test for a grepping utility. Grepping essentially means processing some kind of textual input line by ...

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.