An example of bad test, part 1

time to read 1 min | 124 words

Let us take a look at this test. When I saw it, the test cried out in pain to me: "Help me, I am so overworked."

image

This test is doing far too much. I drew the battle line on the test, just to give you a clear indication on what is going on.

image

What we are asserting are things that have nothing to do with what the test is supposed to test.This is also the classic "A test should have a single assertion" example, I think.

The test pass by side effect. It will actually be a problem down the line.