Package org.robolectric.junit.rules
Class TimeoutRule
java.lang.Object
org.robolectric.junit.rules.TimeoutRule
- All Implemented Interfaces:
org.junit.rules.TestRule
Robolectric's replacement for JUnit's
Timeout.
Timeout spawns a new thread, which is not compatible with
Robolectric's Scheduler. Instead this Rule uses TimeLimitedStatement like @Test(timeout=)
does.
Example usage:
@Rule public final TimeoutRule timeoutRule = TimeoutRule.seconds(40);
@Test
public void testWhichShouldFinishIn40Seconds() {
// ...
}
-
Constructor Summary
ConstructorsConstructorDescriptionTimeoutRule(long timeout, TimeUnit timeUnit) Create aTimeoutRuleinstance with the timeout specified at the timeUnit of granularity of the providedTimeUnit. -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runner.Description description) static TimeoutRulemillis(long millis) Creates aTimeoutRulethat will timeout a test after the given duration, in milliseconds.static TimeoutRuleseconds(long seconds) Creates aTimeoutRulethat will timeout a test after the given duration, in seconds.
-
Constructor Details
-
TimeoutRule
Create aTimeoutRuleinstance with the timeout specified at the timeUnit of granularity of the providedTimeUnit.- Parameters:
timeout- the maximum time to allow the test to run before it should timeouttimeUnit- the time unit for thetimeout
-
-
Method Details
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) - Specified by:
applyin interfaceorg.junit.rules.TestRule
-
millis
Creates aTimeoutRulethat will timeout a test after the given duration, in milliseconds. -
seconds
Creates aTimeoutRulethat will timeout a test after the given duration, in seconds.
-