【问题标题】:JUnit4 Categories results are different between @SuiteClasses vs. TestSuite@SuiteClasses 与 TestSuite 之间的 JUnit4 类别结果不同
【发布时间】:2017-06-24 01:58:27
【问题描述】:

我正在尝试针对 AllTests 测试套件使用类别运行 JUnit4 测试。在运行 Suite3 的示例 1 中,运行 Suite2 的示例 2 产生以下异常。

java.lang.Exception:参数化类上的类别注释 个别方法不支持。

我需要在执行测试时生成 TestSuite。

关于如何纠正问题的任何建议? 谢谢

示例 1

@RunWith(Categories.class)
@IncludeCategory(SlowTest.class)
@SuiteClasses(AllTests3.class)
public class Suite3 {
}

@RunWith(Suite.class)
@SuiteClasses({
           MathUtilTest.class, MathUtil2Test.class
})
public class AllTests3 {
}

示例 2

@RunWith(Categories.class)
@IncludeCategory(SlowTest.class)
@SuiteClasses(AllTests2.class)
public class Suite2 {
}

public final class AllTests2 {
    public static TestSuite suite() {
        final TestSuite result = new TestSuite();
        result.addTest(new JUnit4TestAdapter(MathUtilTest.class));
        result.addTest(new JUnit4TestAdapter(MathUtil2Test.class));
        return result;
    }

    private AllTests2() {
    }

【问题讨论】:

    标签: java junit4


    【解决方案1】:

    在最新的 JUnit 4 (4.12) 稳定版本中存在各种相关的错误:

    https://github.com/junit-team/junit4/issues/1203

    有人对未发布的 4.13-SNAPSHOT 版本进行了修复,您可以通过在 https://github.com/junit-team/junit4 克隆他们的 GitHub 存储库来构建和检查自己

    但是,我自己进行了一些测试,并且不得不得出结论,@Category 注释在您的 MathUtilTest 类上使用时确实有效,但只有当该类被注释时,在单独的测试方法上使用时注释才会被忽略。

    【讨论】:

    • 谢谢。我希望注释方法。将研究构建 4.13 jar。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 2011-12-12
    • 2016-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    相关资源
    最近更新 更多