java - JUnit 有条件地运行测试方法

标签 java junit junit4

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
public class SwiftTest {
    SwiftUtil swiftUtil = new SwiftUtil();
    boolean result;
    @Test
    public void checkInPathFolder()
    {
        result = swiftUtil.checkInPathFolder();
        assertTrue(result);
    }
    @Test
    public void checkCustomObjectExists()
    {
        result=swiftUtil.validateWFId();
        assertTrue(result);
    }
    @Test
    public void runSwift()
    {
        result=swiftUtil.runSwiftBatch();
        assertTrue(result);
    }
    @Test
    public void checkTreatedFolder()
    {
        result=swiftUtil.checkTreatedFolder();
        assertTrue(result);
    }
    @Test
    public void checkExceptionFolder()
    {
        result=swiftUtil.checkExceptionFolder();
        assertTrue(result);
    }
}

以上是我的测试用例。基于两种情况,我想执行上述一组测试方法。

例如:

  1. 在条件 X 上,仅应执行 checkInPathFolder()checkCustomObjectExists()runSwift()
  2. 在条件 Y 上,应执行 checkInPathFolder()runSwift()checkExceptionFolder()

最佳答案

使用JUnit 的assume 机制描述here .如果您想驱动这两个条件,您将需要使用 TheoriesParameterized 来使 JUnit 执行不止一次。

关于java - JUnit 有条件地运行测试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16668430/

相关文章:

java - Maven 多模块项目中的 JUnit 测试抛出 NoClassDefFoundError

java - 使用 fakeRequest 玩 2.5.x junit 测试错误处理

java - 如何从 Windows 命令行永久更新 PATH 变量?

java - Java中的旋转量和方向加密

android - 有什么方法可以在测试类中设置断点吗?

java - 使用 JUnit 在 Eclipse 中运行测试用例

java - Junit测试扫描仪输入问题

java - Google Appengine JAVA - 压缩 blobstore 文件会导致保存回 blobstore 时出现错误 202

java - 如何从 Java SpringBoot 应用程序读取 Azure 应用程序配置值

unit-testing - 如何创建 JUnit 4 测试套件以在抛出预期异常时通过