| [ Team LiB ] |
|
4.10 Repeating Tests4.10.1 ProblemYou want to run certain tests repeatedly. 4.10.2 SolutionUse the junit.extensions.RepeatedTest class. 4.10.3 DiscussionYou may want to run certain tests repeatedly to measure performance or to diagnose intermittent problems.[7] The RepeatedTest class makes this easy:
public static Test suite( ) {
// run the entire test suite ten times
return new RepeatedTest(new TestSuite(TestGame.class), 10);
}
RepeatedTest's first argument is another Test to run; the second argument is the number of iterations. Since TestSuite implements the Test interface, we can repeat the entire test as just shown. Here is how you can build a test suite where different tests are repeated differently: TestSuite suite = new TestSuite( );
// repeat the testCreateFighter test 100 times
suite.addTest(new RepeatedTest(new TestGame("testCreateFighter"), 100));
// run testSameFighters once
suite.addTest(new TestGame("testSameFighters"));
// repeat the testGameInitialState test 20 times
suite.addTest(new RepeatedTest(new TestGame("testGameInitialState"), 20));
4.10.4 See AlsoRecipe 4.14 shows more examples of RepeatedTest. |
| [ Team LiB ] |
|