【问题标题】:Why does JUnit ignore @Category annotations on base classes?为什么 JUnit 忽略基类上的 @Category 注释?
【发布时间】:2014-12-02 11:53:59
【问题描述】:

在我的项目中,碰巧我有一些测试类别的基类。因此,如果我可以将注解 @Category(MyCategory.class) 添加到基类中以将所有子类中的所有测试一次添加到我的类别中,那将很方便。

实际上可以在类级别添加此注解,但 JUnit / surefire 将其忽略在基类上。我认为这种行为不一致且令人困惑。

JUnit 不支持这个有什么原因吗?

【问题讨论】:

标签: java junit junit4 maven-surefire-plugin


【解决方案1】:

正如@RC 所提到的,它取决于 JUnit 的版本。自 2012 年 12 月 5 日起,注解 @Category 被注解为 @Inherited。maven 存储库上的最新官方版本 4.11 于 2012 年 11 月发布。

即将推出的版本仍处于测试阶段:http://mvnrepository.com/artifact/junit/junit

因此,如果您希望将此功能和许多其他功能迁移到 JUnit 4.12,beta-3,风险自负。

【讨论】:

    【解决方案2】:

    事实证明,这不仅是 JUnit 的问题,也是 Maven Surefire 插件的问题。即使使用 JUnit 4.11,使用最新的肯定版本 2.18 继承也很有魅力。

    【讨论】:

    • @AlexR 我不必去测试版 - 仍然使用 JUnit 4.11
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2016-03-08
    • 2014-04-06
    • 2015-02-10
    • 2018-03-10
    • 2021-09-17
    相关资源
    最近更新 更多