@BeforeAll Method as non-static

2019-08-17 08:09发布

I was able to implement a non-static setup method with @BeforeAll annotation. It seems to be working correctly as only gets call once. I am bit confuse as the documentation for @BeforeAll says the method has to be static. Please explain.

@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 {...}
}

标签: junit5
1条回答
女痞
2楼-- · 2019-08-17 09:01

If you want use non-static @BeforeAll and @AfterAll methods you should change test instance lifecycle to per_class.

Look there: 2.10. Test Instance Lifecycle

查看更多
登录 后发表回答