Assertion Roulette & Eager Test

bytedev
2 min readOct 17, 2023

Assertion Roulette is a test smell where it can be difficult to determine which of a number of assertions in a single test is the one that is causing the test to fail.

Though Assertion Roulette is associated with tests that have multiple assertions per test it isn’t necessarily an example of it. In other words just because a test has multiple assertions does not mean it is suffering from the Assertion Roulette test smell.

Assertion Roulette can often be closely associated with the Eager Test smell where a test is trying to verify too much behaviour. An Eager Test will execute several “Act” methods (see the “Arrange Act Assert” pattern) on the system under test often asserting behaviour after each call. In this case the Eager Test should be teased apart into multiple separate tests with one “Act” for each test. In fact a strongly recommended general rule to follow when writing any unit tests is one “Act” per test.

Assertion Roulette can also be related to when an assertion lacks an informative assertion message. For example if you assert that a property of a result should be true and it is instead actually false are you reporting what that actually means? Where the test runner cannot provide adequate information automatically adding a meaningful assertion message can help to assist in working out what is now broken.

--

--