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
ConstructorDescriptionTimeoutRule
(long timeout, TimeUnit timeUnit) Create aTimeoutRule
instance with the timeout specified at the timeUnit of granularity of the providedTimeUnit
. -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runner.Description description) static TimeoutRule
millis
(long millis) Creates aTimeoutRule
that will timeout a test after the given duration, in milliseconds.static TimeoutRule
seconds
(long seconds) Creates aTimeoutRule
that will timeout a test after the given duration, in seconds.
-
Constructor Details
-
TimeoutRule
Create aTimeoutRule
instance 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:
apply
in interfaceorg.junit.rules.TestRule
-
millis
Creates aTimeoutRule
that will timeout a test after the given duration, in milliseconds. -
seconds
Creates aTimeoutRule
that will timeout a test after the given duration, in seconds.
-