JUnit:运行一个具有不同配置的测试 [英] JUnit: Run one test with different configurations
本文介绍了JUnit:运行一个具有不同配置的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2种测试方法,我需要使用不同的配置运行它们
I have 2 test methods, and i need to run them with different configurations
myTest() {
.....
.....
}
@Test
myTest_c1() {
setConf1();
myTest();
}
@Test
myTest_c2() {
setConf2();
myTest();
}
//------------------
nextTest() {
.....
.....
}
@Test
nextTest_c1() {
setConf1();
nextTest();
}
@Test
nextTest_c2() {
setConf2();
nextTest();
}
我无法从一个配置运行它们(如下面的代码所示),因为我需要单独的方法来执行tosca。
I cannot run them both from one config (as in code below) because i need separate methods for tosca execution.
@Test
tests_c1() {
setConf1();
myTest()
nextTest();
}
我不想编写这两种方法来运行每个测试,如何我可以解决这个问题吗?
I don't want to write those 2 methods to run each test, how can i solve this?
首先我想写自定义注释
@Test
@RunWithBothConf
myTest() {
....
}
但也许还有其他解决方案吗?
But maybe there are any other solutions for this?
推荐答案
如何使用 Theories
?
@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
}
不知道为什么如果关闭则格式化。
Not sure why formatting if off.
这篇关于JUnit:运行一个具有不同配置的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文