March 2003
Intermediate to advanced
288 pages
7h 4m
English
You want to run certain tests repeatedly.
Use the
junit.extensions.RepeatedTest
class.
You may want to run certain tests repeatedly to measure performance
or to diagnose intermittent problems.[24] 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));
Recipe 4.14 shows more examples of
RepeatedTest.
[24] Threading bugs are often intermittent.
Read now
Unlock full access