Package | Description |
---|---|
org.junit.rules | |
org.junit.runners |
Provides standard
Runner implementations. |
Class and Description |
---|
ExpectedException
The
ExpectedException rule allows you to verify that your code
throws a specific exception. |
ExternalResource
A base class for Rules (like TemporaryFolder) that set up an external
resource before a test (a file, socket, server, database connection, etc.),
and guarantee to tear it down afterward:
public static class UsesExternalResource {
Server myServer= new Server();
@Rule
public ExternalResource resource= new ExternalResource() {
@Override
protected void before() throws Throwable {
myServer.connect();
};
@Override
protected void after() {
myServer.disconnect();
};
};
@Test
public void testFoo() {
new Client().run(myServer);
}
}
|
MethodRule
A MethodRule is an alteration in how a test method is run and reported.
|
RuleChain
The RuleChain rule allows ordering of TestRules.
|
TestRule
A TestRule is an alteration in how a test method, or set of test methods,
is run and reported.
|
TestWatcher
TestWatcher is a base class for Rules that take note of the testing
action, without modifying it.
|
Timeout
The Timeout Rule applies the same timeout to all test methods in a class:
public static class HasGlobalLongTimeout {
@Rule
public Timeout globalTimeout= new Timeout(20);
@Test
public void run1() throws InterruptedException {
Thread.sleep(100);
}
@Test
public void infiniteLoop() {
while (true) {}
}
}
Each test is run in a new thread.
|
Timeout.Builder
Builder for
Timeout . |
Verifier
Verifier is a base class for Rules like ErrorCollector, which can turn
otherwise passing test methods into failing tests if a verification check is
failed
public static class ErrorLogVerifier {
private ErrorLog errorLog = new ErrorLog();
@Rule
public Verifier verifier = new Verifier() {
@Override public void verify() {
assertTrue(errorLog.isEmpty());
}
}
@Test public void testThatMightWriteErrorLog() {
// ...
}
}
|
Class and Description |
---|
MethodRule
A MethodRule is an alteration in how a test method is run and reported.
|
TestRule
A TestRule is an alteration in how a test method, or set of test methods,
is run and reported.
|
Copyright © 2002–2018 JUnit. All rights reserved.