我有一堆依赖的测试用例(通过dependsOn参数不依赖)并且无法一次运行一个测试。这就是为什么我想运行测试直到达到特定测试。我想停止执行进一步的测试并调用拆卸。
有什么办法可以做到这一点吗?
最佳答案
您可以通过org.junit.Assume.assumeTrue(condition)控制测试用例的执行,如果发现条件为假,则忽略测试用例。在开始时将条件设置为 true,例如,私有(private)静态 boolean 变量可以是用户,并在要执行的最后一个测试用例结束时将条件设置为 false。检查@BeforeTest 中的条件。
示例代码
private static boolean runTest = true;
@org.junit.Before
public void before() throws Exception {
org.junit.Assume.assumeTrue(runTest);
}
@org.junit.Test
public void test1() throws Exception {
// will be executed
}
@org.junit.Test
public void test2() throws Exception {
// will be executed
}
@org.junit.Test
public void test3() throws Exception {
// will be executed
runTest = false;
// no test after this will be executed
}
@org.junit.Test
public void test4() throws Exception {
// will be ignored
}
关于java - 如何仅运行 junit 测试直到达到特定测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479935/