程序包 org.junit.rules
类 ExternalResource
- java.lang.Object
- org.junit.rules.ExternalResource
- 所有已实现的接口:
TestRule
- 直接已知子类:
TemporaryFolder
public abstract class ExternalResource extends Object implements TestRule
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); } }
- 从以下版本开始:
- 4.7
构造器概要
构造器 构造器 说明 ExternalResource()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
after()
Override to tear down your specific external resource.Statement
apply(Statement base, Description description)
Modifies the method-runningStatement
to implement this test-running rule.protected void
before()
Override to set up your specific external resource.
构造器详细资料
ExternalResource
public ExternalResource()
方法详细资料
apply
public Statement apply(Statement base, Description description)
从接口复制的说明:TestRule
Modifies the method-runningStatement
to implement this test-running rule.- 指定者:
apply
在接口中TestRule
- 参数:
base
- TheStatement
to be modifieddescription
- ADescription
of the test implemented inbase
- 返回:
- a new statement, which may be the same as
base
, a wrapper aroundbase
, or a completely new Statement.
before
protected void before() throws Throwable
Override to set up your specific external resource.- 抛出:
Throwable
- if setup fails (which will disableafter
after
protected void after()
Override to tear down your specific external resource.