java - 如何仅运行 junit 测试直到达到特定测试

标签 java junit jenkins-plugins junit4

我有一堆依赖的测试用例(通过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/

相关文章:

java - 如何停止我的服务?

java - 如何在android studio中删除部分安装的sdk

java - Mockito - stub 方法时出现 NullpointerException

java - Jenkins 种子作业(没有这样的文件或目录)

mysql - Jenkins 错误: Authorization failed to svn in sonarqube.

java - Android Studio 中缺少存储库

java - Java 解释器中数学运算的抽象

android - Gradle 依赖 : How to figure out what's causing this duplication

java - 如何使用 jUnit 使用 java 配置类而不使用 XML 来测试 spring mvc 中的 DAO 实现方法

Jenkins - 触发其他项目的参数化构建