问题
In order to integrate with an external test management solution and have visibility of karate results, I need to import them using the JUnit XML report. Test cases identified in JUnit's XML report are identified by the name and classname attributes on the element. However, it seems that these names are being generated somehow dynamicaly and not as unique identifiers that clearly identify the original testcase. The ideal case would be to have unique identifiers for the corresponding testcases, so if we import results multiple times they are always associated with the same entities in the test management solution.
I've tried running the karate-junit5 sample code and ran it using "mvn test". This is a sample of the generated JUnit XML report.
<testcase name="testTags[1][1]" classname="karate.SampleTest" time="0.002"/>
<testcase name="testSample[1][1]" classname="karate.SampleTest" time="0"/>
<testcase name="testSample[1][2]" classname="karate.SampleTest" time="0"/>
<testcase name="testFullPath[1][1]" classname="karate.SampleTest" time="0"/>
I'd expect that the "name" attribute would be filled with an unique identifier for the test case, independent on how many times it will be run, for example with the value of Scenario (e.g. "first hello world")
Feature: sample
Scenario: first hello world
* print 'hello'
Scenario: second scenario
* print 'second'
Thus, having a generate JUnit XML report like this would be something more useful.
<testcase name="second" classname="karate.SampleTest" time="0.002"/>
<testcase name="first hello world" classname="karate.SampleTest" time="0"/>
<testcase name="second scenario" classname="karate.SampleTest" time="0"/>
<testcase name=first" classname="karate.SampleTest" time="0"/>
Or having the name attribute being filled with the feature name plus the scenario name. Anyway, is there any way of configuring how these attributes on the element of the Junit report should be filled?
回答1:
Pretty sure you are using an old version of Karate or something else (maybe JUnit itself) generated this XML. Read this, and you may need to point your reporting solution to a different folder or exclude some files not created by Karate: https://github.com/intuit/karate#test-reports
There certainly may be opportunities to improve Karate so I propose you do this.
Open a new issue, and follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - and then specify what changes you want to what is generated today.
Also the XML creation code is in this file Engine.java look for the saveResultXml()
method.
来源:https://stackoverflow.com/questions/57374797/how-to-configure-the-name-and-classname-attributes-on-the-junit-xml-report