我正在使用JUnit测试套件来运行一些测试,其中一个使用@Parameterized运行多次.我发现当我运行测试时,@ Parameterized函数在@BeforeClass之前运行.这是预期的行为还是其他事情发生了?我原以为@BeforeClass会在任何测试开始之前运行.
这是我的测试套件:
@RunWith(Suite.class)
@SuiteClasses({ Test1.class, Test2.class })
public class TestSuite {
@BeforeClass
public static void setup() throws Exception {
// setup, I want this to be run before anything else
}
}
Run Code Online (Sandbox Code Playgroud)
Test1使用@Parameterized:
public class Test1 {
private String value;
// @Parameterized function which appears to run before @BeforeClass setup()
@Parameterized.Parameters
public static Collection<Object[]> configurations() throws InterruptedException {
// Code which relies on setup() to be run first
}
public Test1(String value) {
this.value = value;
}
@Test
public …Run Code Online (Sandbox Code Playgroud) 我是单元测试的新手.关于@Before在JUnit 4中使用注释的目的.我只是不知道使用它的意义:
public class FoodTestCase {
static private Food sandwich;
@BeforeClass
public static void initialise(){
sandwich = new Sandwich();
}
}
Run Code Online (Sandbox Code Playgroud)
VS
public class FoodTestCase {
static private Food sandwich = new Sandwich();
}
Run Code Online (Sandbox Code Playgroud)
有什么不同?