TestNG - TestNG Test Results - TestNG JUnit Reports - TestNG

How the JUnit reports are generated in TestNG?

For the test execution, simple report XML files are generated by the JUnit tests. As required by the testing, the custom reports can be generated by using XML files. XML files can be used for generating HTML reports as well. The HTML report is generated by taking the JUnit XML files as input by ANT.

TestNG, by default, generates JUnit XML reports for any test execution (in the test-output folder). XML report files are used as input for generating a JUnit HTML report. Consider an example of the same.

Create Test Case Class

A java class, SampleTest.java is created in C:\ > TestNG_WORKSPACE.

Three test methods are provided by the preceding test class. Out of which testMethodOne and testMethodThree are passed when the test is executed and the other method testMethodTwo is made to fail by passing a false Boolean value.

Create testng.xml

The test case is executed by creating testing.xml in C:\ > TestNG_WORKSPACE

By using javac the SampleTest, CustomReporter classes are compiled.

The testng.xml is run.

The output is verified.

A JUnit XML report is made available by the above execution and a simple ANT build configuration XML file is created and an HTML report is generated for the execution of the test.

A new file named build.xml is created under C:\ > TestNG_WORKSPACE folder.

A simple ANT build.xml is defined by having a specific ANT target called junit-report, and which generates a JUnit report while execution. Under the directory test-output/junitreports the target looks for the JUnit report XML files.

Open the command prompt window and go to the C:\ > TestNG_WORKSPACE directory in the command prompt and run the command:

Once executed, a JUnit HTML report will be generated in the configured directory /html-report/Junit. The file junit-noframes.html is opened on the web browser and the following HTML report appears:

JUnit Reports

It is observed that the JUnit XML report is used to generate HTML report by TestNG. By using this method, two kinds of reports can be generated - frames and no-frames. Using frames configuration multiple files can be generated for each class and the main report will connect to them through links. A no-frames report consists of a single file with all the results of the test execution.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

TestNG Topics