【发布时间】:2019-09-07 04:42:59
【问题描述】:
我能够使用@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 {...}
}
【问题讨论】:
-
请出示您的完整代码。
-
如果给定的答案没有阐明你的观点,你应该展示完整的代码,其中至少包括一个带有导入和注释的完整测试类。为什么?因为任何事情都可能有所作为。
-
我已经添加了我正在使用的注释。谢谢。
-
他们确实揭示了发生了什么:-)
标签: junit5