【问题标题】:How to execute JUnit 5 @Tag tests with Ant?如何使用 Ant 执行 JUnit 5 @Tag 测试?
【发布时间】:2017-05-26 11:35:04
【问题描述】:

如何使用 Ant 运行带有 @Tag 注释的 JUnit 5 测试?

例如:

class Tax {
    @Test
    @Tag("taxes")
    void testingTax() {
    }
}

在 Maven 中,我可以执行以下操作来包含或排除。但是我不知道如何让它在 Ant 中工作。

<properties>
    <includeTags>taxes</includeTags>
    <excludeTags>Promo</excludeTags>
</properties>

请多多指教。

【问题讨论】:

  • 您如何从 Ant 启动 JUnit 5 测试?我知道的唯一方法是从 ant 调用 ConsoleLauncher。如果是这种情况,您可以将 -t 参数与您要执行的标签的名称一起传递。到 ConsoleLauncher 的链接:junit.org/junit5/docs/current/user-guide/…
  • 我不是通过 ConsoleLaucher 从 Elipse 启动 JUnit 测试。但是,感谢您告诉我它可以将 -t 参数与标签名称一起使用。 @kotse 谢谢!
  • 啊哈,日食。因此,您正在使用内置的 JUnit5 IDE 支持。我不知道您是否可以从 Eclipse 运行不同的标签 :) 也许您可以将标签名称作为参数传递给您的运行配置,但是 Eclipse 是否实现并支持它 - 我没有尝试过,因为我是 IDEA 用户。
  • 如果您只是在 Eclipse 中运行测试,为什么还要问如何在 Ant 中运行它们?
  • 嗨 Sam,我只是在回答 Kotse 说我通常从 Eclipse 运行,而不是提到 ant 而是 ConsoleLauncher。是的,我仍然在 Ant 中运行注释 @Tag 时遇到问题。有什么线索吗?

标签: junit ant junit5 ant-junit


【解决方案1】:

从 10.7 开始支持。

https://ant.apache.org/manual/Tasks/junitlauncher.html

(includeTags 和 excludeTags)

我也需要它,所以我贡献了它。

【讨论】:

    【解决方案2】:

    根据 Apache Ant 开发人员的说法,目前不支持 JUnit5。但是,根据这个bug report,他们已经开始工作了。还有一个关于这个话题的留言here

    【讨论】:

    • 支持很少——例如不支持分叉
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多