【问题标题】:How to add a JUnit 4 test to a JUnit 3 test suite如何将 JUnit 4 测试添加到 JUnit 3 测试套件
【发布时间】:2013-11-04 16:21:48
【问题描述】:

我想将 JUnit 4 测试添加到使用 JUnit 3 测试套件(“AllTests”)来组织测试的旧项目中。

测试已经使用 JUnit 4 执行,所以我知道 JUnit 4 测试原则上可以工作。我只是忘记了如何将 JUnit 4 测试类添加到 junit.framework.TestSuite 实例。有人知道代码 sn-p 吗?

【问题讨论】:

    标签: junit junit4 test-suite junit3


    【解决方案1】:

    就这么简单:

    public static Test suite() {
        TestSuite suite = new TestSuite("suite name");
        suite.addTestSuite(JUnit3Test.class);
    
        suite.addTest(new JUnit4TestAdapter(JUnit4Test.class));  // <--
    
        return suite;
    }
    

    【讨论】:

      猜你喜欢
      • 2010-10-02
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      相关资源
      最近更新 更多