我能够实现带有@BeforeAll
注释的非静态设置方法。似乎只被调用一次,所以工作正常。我有点困惑,因为文档@BeforeAll
指出该方法必须是静态的。请解释。
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml" })
@TestInstance(Lifecycle.PER_CLASS)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Inherited
public class MyTest
{
@BeforeAll
public void setup() throws Exception {...}
}
Run Code Online (Sandbox Code Playgroud)
Wil*_*son 20
您只需要使用@BeforeAll
下面的代码片段注释您的测试类(包含方法),您就可以开始了。
@TestInstance(Lifecycle.PER_CLASS)
Run Code Online (Sandbox Code Playgroud)
如果要使用非静态@BeforeAll
和@AfterAll
方法,则应将测试实例生命周期更改为per_class
。
看那里:2.10。测试实例生命周期
归档时间: |
|
查看次数: |
910 次 |
最近记录: |