【问题标题】:Surefire JUnit test does not log failed Assume in test xml filesSurefire JUnit 测试不记录失败假设在测试 xml 文件中
【发布时间】:2014-02-25 19:52:38
【问题描述】:

我正在使用

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.16</version>
</plugin>

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
</dependency>

测试我的项目。

我有一个很简单的测试方法

@Test
public void test() throws IOException {
    Assume.assumeTrue("I am broken, so I am ignored", false);
    // some tests
}

当我用maven构建项目时,我在surefire xml文件中得到以下代码sn-p

<testcase name="test" classname="com.stackoverflower.experiment.Test" time="0">
    <skipped/>
</testcase>

我不认为这是 surefire 的正确行为,因为假设失败被视为与忽略相同,它应该遵循与忽略相同的日志记录标准。 This JIRA 明确表示应该记录原因。

你怎么看?有没有办法将该消息放入 xml 文件中?

谢谢

更新 1

我不能使用@Ignore 的原因是我不想将测试硬编码为忽略。我希望根据一些在编码时无法确定的前提条件跳过它。

【问题讨论】:

  • 你的测试类顶部没有@org.junit.Ignore吗?
  • @jw23,请看我的更新

标签: java maven junit surefire


【解决方案1】:

Assume 方法主要用于JUnit Theories,当DataPoints 的组合对给定的Theory 无效时。您应该使用Assert 类,而不是Assume。这是您的示例测试,重新编写以使用正确的类:

@Test
public void test() throws IOException {
    Assert.assertTrue("I am broken", false);
    // some tests
}

这是为了忽略错误的假设,如Javadoc for Assume中所述

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-22
    • 2022-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 2019-05-02
    • 2015-07-04
    相关资源
    最近更新 更多