Java automation testing framework -05-- to give you a makeup test report form a whole - (a) (detailed tutorial)

Brief introduction

  By macro front brother to explain and share presumably little friends, and children's shoes have seen a generation of test reports testng framework, is not what it looks like and it is afraid to let the big guys compliment. So today when a macro brother to return to the beautician, the macro brother to give it beauty beauty; when a back surgeon, to be a plastic surgeon. Surgeon by the macro brother, and give it a full shape. Let her plump, beautiful, lovely number.

Original appearance

After executing test cases, test reports will be generated under the project test-output (default directory)

Open the index.html file, summary of test results, including: package names, the number of successful test cases, test cases fail count, the number of test cases ignored and testng.xml file

Brief test report

Detailed test report

Test cases are successful, the test results to the end of green flag:

Test failures, then test results on red flags:

Click on "Link" link, you can view the contents of testng.xml file:

 

Detailed test results presentation:

Package A (Standard Member)

ReportNG is a fit for you automatically generate a relatively beautiful test reports in the test-output file after running TestNG case!
ReportNG inside Log does not support Chinese, I turn over ReportNG.jar source, specific ways of looking at the bottom, you can also find me directly to jar!
Man of few words said, directly on

 

1. First, take ReportNG source code from GitHub pull, address: https: //github.com/dwdyer/reportng, after downloading unzip good.

2, imported into the editor such as Eclipse, attention: import time to select Maven project import, select the file in the reportng reportng-master directory, as a new project

 (1) Click File-> import

(2) Select Existing Maven Projects, click Next

(3) select Extract good ReportNG project, click Finish

(4) as shown in the project after import, the import remember busy modify the source code, even if you change the code does not change too rotten, and will report the error mess, so you suspect life

(5) project into, to modify the project directory as shown below, and added to the corresponding jar package lib

3, modify the original code

(1) report garbled solution, modify the code AbstractReporter in generateFile this method are as follows

 

 

 Reference Code:

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

Or this can also:

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

(2) modify the test report name, modify ReportMetadata in DEFAULT_TITLE

(3) modify the default generatedBy, the modified reportng.properties generatedBy

(4) modify the default date display, the modified ReportMetadata.java DATE_FORMAT, TIME_FORMAT

(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. Packing, pom.xml right click and select Run As-> Maven install,

 

The console displays BUILD SUCCESS, then build successful, refresh the current project, in the target directory will generate a jar file: reportng-1.8.8.jar

6. test, a new test project (please feel free to everyone), introduced into the corresponding jar package, select Run testng.xml, 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, the modified jar package has been uploaded to the shared group, you need to add a small group of partners can download their own Oh.

Package II (VIP Member)

testng-xslt

testNG generated test report comes less attractive, use testng-xslt landscaping, the following steps:

1, download the official testng-xslt package, http://testng-xslt.googlecode.com/files/testng-xslt-1.1.zip

  Pro-test now google may not access can be made to My Drive in download link: https://pan.baidu.com/s/1HC52IgKBRd9agQ1B8HyfVg extraction code: ferk 

2, after extracting file directory as shown below:

3, copy testng-results.xsl (testng-xslt-1.1 \ src \ main \ resources) files to test-output directory

4, unzip the file testng-xslt-1.1.2, under the saxon-8.7.jar SaxonLiason.jar and lib files copied to project lib folder (if not the new), and introduced to the project (lib folder the path must be placed in test-output, otherwise affect the later build file generation)

 

 

 

5、安装ant,http://mirror.bit.edu.cn/apache/ant/binaries/apache-ant-1.9.4-bin.zip

Ant download and install configuration tutorial
a, Ant Introduction

1, Apache Ant is a Java library and command-line tools, whose task is the process of building a document described as a target and extension points are interdependent. Ant provides a number of built-in tasks, allowing the compilation, assembly, test and run Java applications.

2, Ant is written in Java. Ant users can develop their own include Ant tasks and types of "antlibs", and provide a lot of ready-made commercial or open source "antlibs".

3, similar to Maven, to build a unified project management tool.

Second, download

1, the current latest version: http://mirror.bit.edu.cn/apache//ant/binaries/apache-ant-1.10.5-bin.zip

2, version history download: https://archive.apache.org/dist/ant/binaries/

Third, the installation

1, extract apache-ant-1.10.5-bin.zip

2, the directory structure is as follows:

3, configuration ANT_HOME, Path, classpath

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

4, similar MAVEN_HOME, JAVA_HOME configuration.

Fourth, the test

1, Win + R ---> cmd ---> input ant, appears as follows:

2, see the ant version: ant -version

6, in the project directory, create build.xml file, as follows:

{Name}: name their own projects;
{In}: xml testng is generated corresponding to the report; (without creating a path specified)
{Style}: corresponding report is generated testng XSL; (without creating a path specified)
{Out}: testNG-xslt is to use to generate the report file name and path; (to create a new file may be assigned to the test-output)
{Expression}: testNG-xslt use is the path to generate a report;
<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" >
        <!-- 需要根据自己的环境进行配置(将E:/ workspace / testNG / replace your project's directory) inXSLT<->
        = "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 "  > 
             ! <- need to be configured according to your environment (the E: / workspace / testNG / replace your project's directory) -> 
            < param name =" testNgXslt.outputDir " expression the = "F.: / Workspace / hongge / Output-Test /"  /> 
            < CLASSPATH the refid = "test.classpath"  /> 
        </ XSLT > 
    </ target > 
</ Project > 

7, in the cmd, switch to the project directory, execute ant transform:

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

summary

Well, here today share.

There are problems to join java automated testing exchange group: 694 280 102

 

No individual public                                                              micro-channel group  (group of micro-channel 100 is full, you can add micro Nobuhiro brother pull you into the group, please note: into the group)          

                                                                 

I am sure that your progress is. If you feel good, you are encouraged to ask about it! Remember dimples  recommended  Oh! ! ! (Click on the right side of the ball you can! (^ __ ^) hee hee ......)

 

Guess you like

Origin www.cnblogs.com/du-hong/p/11697592.html