Don't Play Roulette With Your Test Runner

Avoid writing tests that verify multiple assertions within a single test method.  Numerous assertions make it difficult to determine which one caused a test to fail — inhibiting Defect Localization.  This anti-pattern is often caused by Eager Tests that try to minimize the number of tests we need to write.  Apply the Extract Function refactoring to tease apart these tests into single-condition tests so that the reasons for test failures are obvious.

Writing a Better Test

Figure 1 below illustrates a test method using multiple assertions to verify FizzBuzz results.  As noted, separate test methods should be created for each assert.

Figure 1 - Refactoring an Eager Test

Figure 2 shows separate tests for each of the assertions.  Not only does this greatly enhance Defect Localization, but the code is more readable.

Figure 2 - Extracted Tests