如何在Junit XML报告中创建嵌套的testsuite标签

时间:2019-08-20 16:22:45

标签: unit-testing junit automated-tests junit4 cucumber-jvm

我正在尝试使用JenkinsCI / Testrail-plugin将自动BDD(cucumber-jvm)测试结果报告给TestRail。 TestRail UI具有可配置的文件夹(称为“版块”)。当前报告将仅进入“根”文件夹/部分。为了使结果能够将结果报告到TestRailUI的小节中,我需要一个JUnit XML报告,该报告在各节下可以具有嵌套。当我手动编辑报告时,它使我能够报告明智的层次结构。

我不确定JUNIT是否支持这种结构,但是我一直在努力使其得以实现。似乎是在“幕后”创建了嵌套套件,但我认为这些套件会在(surefire)报告时间变平。

我要从左到右,如下所示: Jenkins(Cucumber-JVM项目)-> JunitXML-> Jenkinsci / testrail-plugin-> TestRail“部分”。

有人成功做到了吗,或者有人可以看到将我的代码用作模板的方法吗?请参阅https://github.com/systemsincode/cucumber-java-skeleton-TestRail/tree/AddingJunitSuitesSupport的AddingJunitSuitesSupport分支 (请克隆并通过以下方式运行:mvn test -Dtest = ROOTElement)

我遵循了其他SO示例,并且我相信我已经创建了一个测试项目,该项目将使用以下方法创建测试套件:

@RunWith(Suite.class)
@Suite.SuiteClasses({
        com.example.ClassThatIsRunViaCumumber
})

当我与嵌套类一起使用时,这会创建嵌套的测试套件。但是,测试结果似乎被推到了最高的测试套件中。

//package io.cucumber.skeleton;

import io.cucumber.skeleton.RunCucumberTest;
import io.cucumber.skeleton.RunCucumberTestFeature2;
import io.cucumber.skeleton.RunCucumberTestFeature3;

import org.junit.runner.*;
import org.junit.runners.*;

@RunWith(Suite.class)
@Suite.SuiteClasses({
        ROOTElement.SubSuite1.class,
        //  ROOTElement.SubSuite1.SubSubSuite1.class (moved to       SubSuite1)
        ROOTElement.SubSuite2.class
})

public class ROOTElement {
    // the class remains empty,
    // used only as a holder for the above annotations

    @RunWith(Suite.class)
    @Suite.SuiteClasses({
            RunCucumberTest.class,
            ROOTElement.SubSuite1.SubSubSuite1.class
    })

    public static class SubSuite1 {
        // the class only holds the sub sub suite code
        @RunWith(Suite.class)
        @Suite.SuiteClasses({
                RunCucumberTestFeature3.class
        })
        public static class SubSubSuite1 {
            // the class remains empty,
            // used only as a holder for the above annotations
        }

    }

    @RunWith(Suite.class)
    @Suite.SuiteClasses({
            RunCucumberTestFeature2.class
    })

    public static class SubSuite2 {
        // the class remains empty,
        // used only as a holder for the above annotations
    }
}

期望的安全文件夹XML(或更理想!):

<testsuite name="ROOTElement">
  <testsuite name="SubSuite1">
  ...featurefile 1 results here
    <testsuite name="SubSubSuite1">
    ...featurefile 3 results here
    </testsuite>
  </testsuite>
  <testsuite name="SubSuite2">
  ...featurefile 2 results here    
  </testsuite>
</testsuite>

实际:

<testsuite name="ROOTElement">
   ...featurefile 1 results here
   ...featurefile 3 results here
   ...featurefile 2 results here
</testsuite>

当我在intellij中执行ROOTElement时,似乎可以正确理解嵌套,尽管它不能用于testrail,但嵌套了它的XML输出。

0 个答案:

没有答案
相关问题