Java automation test framework-05 - to make up the whole shape of your test report


brief introduction

Through the explanation and sharing of Hongge, I think that my friends and children's shoes have seen the test report generated by the testng framework, and I don't dare to let you compliment it for its appearance and appearance. Today, Hongge will be a beautician, and Hongge will give it beauty treatment; he will be a surgeon, and he will be a plastic surgeon. From brother Hong to master the knife, and reshape it. Let her be plump, beautiful and lovely.

Original appearance

After executing the test case, the test report will be generated under the test output (default directory) of the project

Open the index.html file and summarize the test results, including the suite name, the number of test case successes, the number of test case failures, the number of test case omissions and the testng.xml file

Brief test report

Detailed test report

If all test cases are successful, the test results are marked with a green background:

If the test case fails, the test result is marked with a red background:

Click the "Link" Link to view the contents of testng.xml file:


Detailed test results:

Package 1 (ordinary member)

ReportNG is a relatively beautiful test report generated in the test output file after running case with TestNG!
Log in ReportNG does not support Chinese. I changed the source code of ReportNG.jar. For details, see the bottom. You can also ask me for jar directly!
Don't talk too much. Go straight


1. First, pull the source code of ReportNG from GitHub,, download it and extract it.

2. Import to an editor such as Eclipse. Note: when importing, please select Maven project import. Please select the report ng file under the report ng master directory as the new project

(1) click file - > Import

(2) Select Existing Maven Projects and click Next

(3) Select the decompressed reporting project and click Finish

(4) The imported project is as shown in the figure. After importing, remember to be busy modifying the source code. Even if you change the code badly, you can also change it wrong, and will report a mess of errors, which makes you doubt your life

(5) After the project is imported, modify the project to the directory shown in the figure below, and add the corresponding jar package to lib


3. Modify the original code

(1) To solve the problem, modify generateFile in AbstractReporter as follows



Reference code:

OutputStream out = new FileOutputStream(file);
 Writer writer = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));

Or you can:

OutputStream out = new FileOutputStream(file);
 Writer writer = new BufferedWriter(new OutputStreamWriter(out,ENCODING));

(2) Modify the test report name and the default? Title in ReportMetadata

(3) Modify the default generatedBy and generatedBy in

(4) Modify the default date display, and modify date? Format, time? Format in

(5) Modify pom.xml

<?xml version="1.0" encoding="UTF-8"?>
  <project xmlns=""
                             <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
                    <!--  <suiteXmlFiles>
                     </suiteXmlFiles> -->

4. Package. Right click pom.xml and select run as - > Maven install,


5. If the console displays BUILD SUCCESS, the build is successful. Refresh the current project, and a jar file will be generated under the target directory: reportng-1.8.8.jar

6. Test, create a new test project (please feel free), import the corresponding jar package, choose to run testng.xml, and remember to add

  1. <listeners>
  2. <listener class-name="org.uncommons.reportng.HTMLReporter" />
  3. <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
  4. </listeners>

7. The report shows that the modified jar package has been uploaded to the group share, and the required small partners can add the group to download by themselves.

Package 2 (VIP member)


The test report generated by testNG is not very beautiful. You can beautify it with testNG XSLT as follows:

1. Download the TestNG XSLT package on the official website,

google may not be able to access it now. You can download it from my online disk. Link: Extraction code: ferk

2. The extracted file directory is shown as follows:

3. Copy the testng-results.xsl (testng-xslt-1.1\src\main\resources) file to the test output directory

4. Extract the testng-xsl-1.1.2 file, copy the saxon-8.7.jar and SaxonLiason.jar under the lib file to the lib folder of the project (if not, create a new one), and import them into the project (the path of the lib folder must be under test output, otherwise the generated build file will be affected later)




5. Install ant,

Ant download installation configuration tutorial
1, About Ant

1. Apache Ant is a Java library and command-line tool whose task is to rely on the processes described in the build file as targets and extension points. Ant provides many built-in tasks that allow you to compile, assemble, test, and run Java applications.

2. Ant is written in Java. Ant users can develop their own "ant LIBS" that contain ant tasks and types, and provide a large number of off the shelf commercial or open source "ant LIBS".

3. Similar to Maven, a unified project management tool.

2, Download

1. Current latest version:

2. Download historical version:

3, Installation

1. Unzip

2. The directory structure is as follows:

3. Configure ant home, path, classpath

ANT_HOME = F:\soft\ant-1.10.5
Path = %ANT_HOME%\bin;
classpath = %ANT_HOME%\lib;

4. Similar to the configuration of make home and Java home.

4, Testing

1. Win + R - > CMD - > Enter ant, as shown below:

2. View ant version: ant version

6. In the project directory, create a new build.xml file, as follows:

{name}: own project name;
{in}: corresponds to the xml of testng generated report; (specifying the path does not need to be created)
{style}: corresponding to the xsl of testng generated report; (specifying the path does not need to be created)
{out}: is the filename and path of the report to be generated with TestNG XSLT; (you can create a new file or specify it to test output)
{expression}: is the path to generate the report with TestNG XSLT;
<project name="hongge" basedir="." >
    <property name="lib.dir" value="lib" />
    <path id="test.classpath" >
         <!-- adding the saxon jar to your classpath -->
        <fileset dir="${lib.dir}" includes="*.jar" />
    <target name="transform" >
        <!-- It needs to be configured according to its own environment E:/workspace/testNG/Replace with yourself project Contents of) -->
        <xslt in="F:/workspace/hongge/test-output/testng-results.xml" style="F:/workspace/hongge/test-output/testng-results.xsl"
  out="F:/workspace/hongge/test-output/index1.html" >
             <!-- It needs to be configured according to its own environment E:/workspace/testNG/Replace with yourself project Contents of) -->
            <param name="testNgXslt.outputDir" expression="F:/workspace/hongge/test-output/" />
            <classpath refid="test.classpath" />

7. In cmd, switch to the project directory and execute ant transform:

8. Under the configuration path, open the generated file index1.html to display the test results in a graphical interface:


Tags: Apache xml Maven Java

Posted on Sat, 09 May 2020 04:00:09 -0400 by BuckeyeTheDog