@BeforeAll Method as non-static

隐身守侯 提交于 2019-12-24 20:16:14

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/55719014/beforeall-method-as-non-static

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!