【发布时间】:2020-12-02 19:03:13
【问题描述】:
我需要使用扩展在使用它的类中的所有测试用例之前和之后运行代码。我的测试类需要访问我的扩展类中的一个字段。这可能吗?
给定:
@ExtendWith(MyExtension.class)
public class MyTestClass {
@Test
public void test() {
// get myField from extension and use it in the test
}
}
和
public class MyExtension implements
BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback {
private int myField;
public MyExtension() {
myField = someLogic();
}
...
}
如何从我的测试类访问myField?
【问题讨论】: