The
TimedTest is a test decorator that runs a test and measures the elapsed time of the test.
A TimedTest is constructed with a specified maximum elapsed time. By default, a TimedTest will wait for the completion of its decorated test and then fail if the maximum elapsed time was exceeded. Alternatively, a TimedTest can be constructed to immediately signal a failure when the maximum elapsed time of its decorated test is exceeded. In other words, the TimedTest will not wait for its decorated test to run to completion if the maximum elapsed time is exceeded.
For example, to decorate the ExampleTest as a TimedTest that waits for the ExampleTest test case to run to completion and then fails if the maximum elapsed time of 2 seconds is exceeded, use:
Test timedTest = new TimedTest(new TestSuite(ExampleTest.class), 2000);
or, to time a single test method, use:
Test timedTest = new TimedTest(new ExampleTest("testSomething"), 2000);
Alternatively, to decorate the ExampleTest.testSomething() test as a TimedTest that fails immediately when the maximum elapsed time of 2 seconds is exceeded, use:
Test timedTest = new TimedTest(new ExampleTest("testSomething"), 2000, false);
@author
Mike Clark
@author Clarkware Consulting, Inc.
@author Ervin Varga