我有2个测试方法,我需要用不同的配置来运行它们
myTest() {
.....
.....
}
@Test
myTest_c1() {
setConf1();
myTest();
}
@Test
myTest_c2() {
setConf2();
myTest();
}
//------------------
nextTest() {
.....
.....
}
@Test
nextTest_c1() {
setConf1();
nextTest();
}
@Test
nextTest_c2() {
setConf2();
nextTest();
}
我不能从一个配置中同时运行它们(如下面的代码所示),因为我需要单独的方法来执行 tosca。
@Test
tests_c1() {
setConf1();
myTest()
nextTest();
}
我不想编写这 2 个方法来运行每个测试,我该如何解决这个问题?
首先我想写自定义注释
@Test
@RunWithBothConf
myTest() {
....
}
但也许还有其他解决方案?
最佳答案
如何使用理论
?
@RunWith(Theories.class)
public class MyTest{
private static enum Configs{
C1, C2, C3;
}
@DataPoints
public static Configs[] configValues = Configs.values();
private void doConfig(Configs config){
swich(config){...}
}
@Theory
public void test1(Config config){
doConfig(config);
// rest of test
}
@Theory
public void test2(Config config){
doConfig(config);
// rest of test
}
不知道为什么格式化关闭。
关于java - JUnit:使用不同的配置运行一个测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13073419/