How to generate JUnit style XML report using TestNG?
Asked Answered
M

1

8

I'm using TestNG framework for our integration testing. I want to generate JUnit style XML report using TestNG. My project does not use Ant but we use Maven. Can you please tell what is the format of JUnit style XML looks like and how to generate JUnit XML files using TestNG API. Later I want to integrate this JUnit XML file with Hudson and I even want to customize this JUnit XML report using TestNG.

So How can I do the above tasks?

Mok answered 8/11, 2012 at 11:54 Comment(1)
When I run mvn test "-DsuiteXmlFile=${suiteFile}" then I see a new file named ./target/surefire-reports/TEST-TestSuite.xml was created. It Is in jUnit.xml format.Shearwater
B
9

TestNG already generates these files, look under test-output/junitreports.

Brandonbrandt answered 9/11, 2012 at 5:43 Comment(4)
Thanks for your comments. I want to use TestNG API to override the reporting functionality. How to do it? For example: if you look at the JUnit HTML you will see that Hudson groups things by class/package names. So if we want to get different grouppig in HUdson HTML reports. we need to change the way how XML is generated. For instance we can put test name instead of class/package in XML.Mok
Look up the documentation for IReporter or ITestListener: testng.org/doc/documentation-main.html#loggingBrandonbrandt
Thanks for your comments. I have implemented IReporter interface to generate my customized report. It generates JUnit XML format supported by Hudson. Now I have another question: How can I get run time information of Hudson when I run reports. The reason for asking is this: I have master Hudson server which has some jobs configured as Hudson slaves and my Hudson slave is running on another server NOT on master Hudson server. When I run reports on my Hudson slave I should display the reports. But my JUnit report XML files are available on my Hudson slave but Hudson is not able to pick.Mok
The JUnit attachments plugin is installed and configured on master hudson server and Hudson slaves will get the properties of master hudson server by using archiving files option. Hence "Publish JUnit Reports" option is not available on slave Hudson.Mok

© 2022 - 2024 — McMap. All rights reserved.