简体   繁体   English

有没有办法强制Maven Surefire或JUnit在从Test Suite执行时指出失败的测试类的名称?

[英]Is there a way to force Maven Surefire or JUnit to indicate the name of the failing test class when executed from a Test Suite?

My question: Is there a way to force Maven Surefire (or JUnit?) to indicate the name of the failing test class when this class has been executed from a Test Suite? 我的问题:当从Test Suite执行此类时,是否有办法强制Maven Surefire(或JUnit?)指示失败的测试类的名称?

Now, the long story. 现在, 漫长的故事。

Imagine you have a JUnit test suite that launches two JUnit tests. 想象一下,你有一个JUnit测试套件,可以启动两个JUnit测试。

Examples of test classes: 测试类的示例:

public class TestOne {

    @Test
    public void foo() {
        assertTrue(false);
    }

    @Test
    public void bar() {
        assertTrue(false);
    }

}

@UnitTest
public class TestTwo {

    @Test
    public void foo() {
        assertFalse(true);
    }

}

and the test suite: 和测试套件:

@RunWith(Suite.class)
@SuiteClasses(value = { TestOne.class, TestTwo.class })
public class MySuite {

}

Now, if I run the test suite ( mvn test -Dtest=MySuite ), I will have the following errors: 现在,如果我运行测试套件( mvn test -Dtest=MySuite ),我将mvn test -Dtest=MySuite以下错误:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running caf.opm.preclosing.junit.MySuite
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!

Results :

Failed tests:
  foo(my.project.junit.TestOne)
  bar(my.project.junit.TestOne)
  foo(my.project.junit.TestTwo)

Tests run: 3, Failures: 3, Errors: 0, Skipped: 0

So reading these lines, I can easily detect which classes and tests are failing. 因此,阅读这些内容,我可以轻松地检测哪些类和测试失败。

However, in target/surefire-reports/ directory, I have only one file, MySuite.txt where the three tests are failing. 但是,在target/surefire-reports/目录中,我只有一个文件MySuite.txt ,其中三个测试失败。 One of the consequences of such situation is that my Hudson build will show me the following information: 这种情况的后果之一是我的Hudson版本将向我显示以下信息:

All Failed Tests
Test Name       Duration    Age   
>>> my.project.junit.MySuite.foo    0.0 1
>>> my.project.junit.MySuite.bar    0.0 1
>>> my.project.junit.MySuite.foo    0.0 1

As you can see, it becomes harder to identify the failing tests, and for example, as TestOne.foo() and TestTwo.foo() failed, I saw two MySuite.foo errors in my JUnit report. 正如您所看到的,识别失败的测试变得更加困难,例如,当TestOne.foo()TestTwo.foo()失败时,我在JUnit报告中看到了两个MySuite.foo错误。 Of course I can retrieve the name of the test class by reading the logs of the failed test, but it's not really a solution... 当然,我可以通过读取失败测试的日志来检索测试类的名称,但它并不是真正的解决方案......

So my question is to know if I can force Surefire (or JUnit?) to indicate the name of test class. 所以我的问题是要知道我是否可以强制Surefire(或JUnit?)来指示测试类的名称。

Thanks. 谢谢。

I get a single file per test class, so it took me a moment to figure this one out: You're using a test suite. 每个测试类我得到一个文件,所以我花了一点时间来解决这个问题:你正在使用测试套件。

When using test suites, all the test results end up in a single file with the name of the suite. 使用测试套件时,所有测试结果都以一个文件结尾,并带有套件名称。

There is no option to change this behavior. 没有选项可以更改此行为。 Try to file a feature request . 尝试提交功能请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM