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

From: https://www.cnblogs.com/du-hong/p/11697592.html

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, https://github.com/dwdyer/reportng, 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 reporting.properties

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

(5) Modify pom.xml

<?xml version="1.0" encoding="UTF-8"?>
  <project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
  
      <groupId>reportng</groupId>
      <artifactId>reportng</artifactId>
      <version>1.8.8</version>
     <dependencies>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
             <version>4.3.6</version>
         </dependency>
 
         <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.0</version>
        </dependency>
 
         <dependency>
             <groupId>org.testng</groupId>
             <artifactId>testng</artifactId>
             <version>6.9.6</version>
         </dependency>
 
         <dependency>
             <groupId>org.uncommons</groupId>
             <artifactId>reportng</artifactId>
             <version>1.1.4</version>
             <scope>test</scope>
             <exclusions>
                 <exclusion>
                     <groupId>org.testng</groupId>
                     <artifactId>testng</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
 
         <dependency>
             <groupId>com.google.inject</groupId>
             <artifactId>guice</artifactId>
             <version>3.0</version>
             <!--<scope>test</scope>-->
         </dependency>
     </dependencies>
 
     <build>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.18.1</version>
                 <configuration>
                     <properties>
                         <property>
                             <name>usedefaultlisteners</name>
                             <value>false</value>
                         </property>
                         <property>
                             <name>listener</name>
                             <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
                         </property>
                     </properties>
                    <!--  <suiteXmlFiles>
                         <suiteXmlFile>testng.xml</suiteXmlFile>
                     </suiteXmlFiles> -->
                     <workingDirectory>target/</workingDirectory>
                 </configuration>
             </plugin>
         </plugins>
     </build>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 </project>

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)

testng-xslt

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, http://testng-xslt.googlecode.com/files/testng-xslt-1.1.zip

google may not be able to access it now. You can download it from my online disk. Link: https://pan.baidu.com/s/1HC52IgKBRd9agQ1B8HyfVg 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, http://mirror.bit.edu.cn/apache/ant/binaries/apache-ant-1.9.4-bin.zip

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: http://mirror.bit.edu.cn/apache//ant/binaries/apache-ant-1.10.5-bin.zip

2. Download historical version: https://archive.apache.org/dist/ant/binaries/

3, Installation

1. Unzip apache-ant-1.10.5-bin.zip

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" />
    </path>
    <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" />
        </xslt>
    </target>
</project>

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:

Summary

Tags: Apache xml Maven Java

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