【发布时间】:2022-01-21 19:10:08
【问题描述】:
我有一个带有 @BeforeAll 和 @AfterAll 注释的简单 Junit 5 Siute。套件已执行,但这些方法在所有类执行之前和之后都不会执行。
package demo;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectClasses({ demo.TestDemoClass1.class, demo.TestDemoClass2.class })
public class TestSuite {
@BeforeAll
public static void start() throws Exception {
System.out.println("Before All from Suite1");
}
@AfterAll
public static void end() throws Exception {
System.out.println("After All from Suite1");
}
}`
【问题讨论】:
-
如果它解决了我的要求,如果你接受它作为答案,我会添加一个答案。
-
也许你想要一个
TestExecutionListener代替? -
您正在混合两种无法混合的东西。从导入的包中可以看出 Suite 是由 Suite 引擎处理的。 Before/AfterAll 来自木星,这就是为什么必须将它们添加到您的测试类中。
-
@johanneslink 套件引擎中没有可使用的注释?我搜索了很多,但套件级别没有任何注释
-
另外@Lunatic 当我在 Suite 类上添加 ExtendWith 时,您的链接 stackoverflow.com/questions/43282798/… 这里提到的步骤不起作用