@BeforeAll方法为非静态 [英] @BeforeAll Method as non-static

查看:556
本文介绍了@BeforeAll方法为非静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用@BeforeAll注释实现非静态设置方法. 似乎只被调用一次,因此工作正常. 我有点困惑,因为@BeforeAll的文档说该方法必须是静态的.请解释.

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

推荐答案

如果要使用非静态@BeforeAll@AfterAll方法,则应

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

看那里: 2.10.测试实例生命周期

这篇关于@BeforeAll方法为非静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆