在下面使用此方法时,通过设置带有套件的 jUnit。当每个测试类中的所有 @BeforeClass 都将在任何测试开始执行之前执行时,我们遇到了问题。 (对于@BeforeClass运行的每个n个TestClass文件,然后在它们执行后,它开始执行第一个MyTest.class文件@Test)
这将导致我们分配大量资源和内存。我的想法是它一定是错误的,每个@BeforeClass 不应该只在实际测试类执行之前运行,而不是在套件启动时运行吗?
@RunWith(Suite.class)
@Suite.SuiteClasses({ MyTests.class, Mytests2.class, n1, n2, n })
public class AllTests {
// empty
}
public class MyTests { // no extends here
@BeforeClass
public static void setUpOnce() throws InterruptedException {
...
@Test
...
public class MyTests2 { // no extends here
@BeforeClass
public static void setUpOnce() throws InterruptedException {
...
@Test
...
原文由 Andreas Mattisson 发布,翻译遵循 CC BY-SA 4.0 许可协议
在
AllTests
类中写一个@BeforeClass
方法,套件启动时执行。输出: