Java 使用Maven Surefire保留JUnit XML报告结构

Java 使用Maven Surefire保留JUnit XML报告结构,java,maven,gitlab-ci,junit5,maven-surefire-plugin,Java,Maven,Gitlab Ci,Junit5,Maven Surefire Plugin,在通过maven测试创建报告时,我希望保留JUnit样式的XML报告。 我正在使用JUnit5的特性,例如DynamicTest(TestFactory),嵌套的,参数化测试。 这些特性使我能够组织测试,从而在EclipseIDE中显示测试结果 在Eclipse中运行JUnit5测试时,我得到了测试的结构化视图。但是对于Maven surefire(Maven surefire插件:3.0.0-M4),报告只是在一个平面层次结构中 例如: public class Example { @

在通过maven测试创建报告时,我希望保留JUnit样式的XML报告。 我正在使用JUnit5的特性,例如
DynamicTest
TestFactory
),
嵌套的
参数化测试
。 这些特性使我能够组织测试,从而在EclipseIDE中显示测试结果

在Eclipse中运行JUnit5测试时,我得到了测试的结构化视图。但是对于Maven surefire(Maven surefire插件:3.0.0-M4),报告只是在一个平面层次结构中

例如:

public class Example {
    @Nested
    public class ExampleA {
        @ParameterizedTest
        @ValueSource(strings = {"Foo1A", "Bar1A"})
        void test1A(String input) {}

        @ParameterizedTest
        @ValueSource(strings = {"Foo2A", "Bar2A"})
        void test2A(String input) {}

    }
    @Nested
    public class ExampleB {
        @ParameterizedTest
        @ValueSource(strings = {"FooB", "BarB"})
        void testB(String input) {}
    }
}
在Eclipse中运行时的结果:

当作为surefire report运行时:
mvn-Dtest=Example*clean test
会产生三个文件:一个为空的用于父测试用例,两个为扁平的用于嵌套测试用例。它们还缺少与类名的关联。因此类
ExampleA
的报告如下所示:


有没有一种方法可以生成junit风格的XML报告,用maven保存结构?我的目标是在中显示测试结果。

您使用哪一版本的maven surefire插件?最新版本:3.0.0-M4。我把它添加到了原来的帖子中,我认为在结构上显示这些内容超出了生成结果XML的范围。Jenkins解析JUnitXML以创建结构化/排序的html。我不确定gitlab ci,但我认为他们有一个类似的插件。如果没有,您可以签入clover并获得代码覆盖率报告。gitlab ci也能够解析junit xml报告。我不确定这些限制是什么,因为我一直在用maven surefire复制结构化视图。但如果你能用RecCom和其他插件来生成这些测试报告,我很感激。我只需要在我的应用程序中根据它们的测试类执行测试,并需要一个更深层的xml测试结果树,代表我创建的junit5测试层次结构。经过进一步研究,junit5生成的xml报告似乎存在局限性。自2016年以来,存在一个有待解决的问题,以改进背后的XSD。但我不能100%肯定这是一个正确的结论。您使用哪个版本的maven surefire插件?最新版本:3.0.0-M4。我把它添加到了原来的帖子中,我认为在结构上显示这些内容超出了生成结果XML的范围。Jenkins解析JUnitXML以创建结构化/排序的html。我不确定gitlab ci,但我认为他们有一个类似的插件。如果没有,您可以签入clover并获得代码覆盖率报告。gitlab ci也能够解析junit xml报告。我不确定这些限制是什么,因为我一直在用maven surefire复制结构化视图。但如果你能用RecCom和其他插件来生成这些测试报告,我很感激。我只需要在我的应用程序中根据它们的测试类执行测试,并需要一个更深层的xml测试结果树,代表我创建的junit5测试层次结构。经过进一步研究,junit5生成的xml报告似乎存在局限性。自2016年以来,存在一个有待解决的问题,以改进背后的XSD。但我不能100%肯定这是一个正确的结论。
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0.0-M4" name="ExampleA" time="5.69" tests="4" errors="0" skipped="0" failures="0">
  <properties>
  ...
  </properties>
  <testcase name="[1] Foo1A" classname="ExampleA" time="0.185"/>
  <testcase name="[2] Bar1A" classname="ExampleA" time="0.003"/>
  <testcase name="[1] Foo2A" classname="ExampleA" time="0.003"/>
  <testcase name="[2] Bar2A" classname="ExampleA" time="0.003"/>
</testsuite>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <argLine>
                --illegal-access=permit
            </argLine>
            <statelessTestsetReporter
                implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
                <disable>false</disable>
                <version>${maven-surefire-plugin.version}</version>
                <usePhrasedFileName>true</usePhrasedFileName>
                <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
                <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
                <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
            </statelessTestsetReporter>
            <consoleOutputReporter
                implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5ConsoleOutputReporter">
                <disable>false</disable>
                <encoding>UTF-8</encoding>
                <usePhrasedFileName>false</usePhrasedFileName>
            </consoleOutputReporter>
            <statelessTestsetInfoReporter
                implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
                <disable>false</disable>
                <usePhrasedFileName>false</usePhrasedFileName>
                <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
                <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
            </statelessTestsetInfoReporter>
        </configuration>
    </plugin>