Background:

First, jMeter was used to record or write performance test scripts, maven was used to add related dependencies, and the performance test codes were submitted to Github. In Jenkins, Git was configured to download the performance test codes, configure the running scripts and test reports, and configure the failure to automatically send email notification. In this way, the performance test job was configured. Then, we configure the performance test job as the downstream job of the development job. Once the development has a new code to submit and run the development job, it will automatically trigger our performance test job. In this way, we can fully automate the interface performance test, and we only need to pay attention to the failed test email!

1 Environment Construction

  • Download and install JDK & Eclipse.
  • Download and install Jenkins.
  • Download Maven and unzip it.
  • Download JMeter and unzip it.

2 Prepare performance test scripts

  • Start JMeter (double-click bin\jmeter.bat in the jMeter decompression directory).
  • Write test cases in Jmeter and export them (recommended).

  • Or you can record the script with JMeter and export it after making sure it passes.
  • Of course you can choose to record the script with Badboy and make sure it runs well before exporting it.

3 Create a Maven project for the performance test script

  • Open Eclipse and create a Maven project.
  • Create a JMeter folder in the SRC /test/ directory and copy the prepared performance test scripts to this folder.

  • Create a resource folder in the SRC /test/ directory and copy the test template (E:\apache-jmeter-3.2\apache-jmeter-3.2\extras file below) into this resource file.

  • Copy the following files from apache-jmeter-3.2\bin to the SRC /test/jmeter file.

  • Add jmeter-maven-plugin to the maven script:
<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>com.performance.test</groupId>
    <artifactId>PushNotificationPerformanceTest</artifactId>
    <version>0.0.1 - the SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>PushNotificationPerformanceTest</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jmeter.result.jtl.dir>${project.build.directory}\jmeter\results</jmeter.result.jtl.dir>
        <jmeter.result.html.dir>${project.build.directory}\jmeter\html</jmeter.result.html.dir>
        <jmeter.result.html.dir1>${project.build.directory}\jmeter\html1</jmeter.result.html.dir1>
        <ReportName>TestReport</ReportName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.1.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xml-maven-plugin</artifactId>
                <version>1.0 - beta - 3</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>transform</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <transformationSets>
                        <transformationSet>
                            <dir>${jmeter.result.jtl.dir}</dir>
                            <stylesheet>src\test\resources\jmeter-results-report-loadtest.xsl</stylesheet>
                            <outputDir>${jmeter.result.html.dir}</outputDir>
                            <fileMappers>
                                <fileMapper
                                    implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>html</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                        <transformationSet>
                            <dir>${jmeter.result.jtl.dir}</dir>
                            <stylesheet>src\test\resources\jmeter.results.shanhe.me.xsl</stylesheet>
                            <outputDir>${jmeter.result.html.dir1}</outputDir>
                            <fileMappers>
                                <fileMapper
                                    implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>html</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                    </transformationSets>
                </configuration>
                <! -- using XSLT 2.0 -->
                 <dependencies>
                   <dependency>
                   <groupId>net.sf.saxon</groupId>
                   <artifactId>saxon</artifactId>
                   <version>8.7</version>
                   </dependency>
               </dependencies>
            </plugin>
        </plugins>
    </build>
</project>Copy the code

4 Run the performance test script in Eclipse

  • Right-click the project for the performance test and select Run as – from the drop-down list. Then add verify to Goals in the pop-up dialog box and click Run.

  • After running, there will be a test result file as shown below

5 Run the performance test script in Jenkins and configure the test results

  • You can create a Maven job Git plugin for Jenkins, which is used to download the performance test code from Github. The Performance plugin, which displays Performance reports; HTML Publisher Plugin that displays reports of related interface test results.
  • Create maven Job in Jenkins

  • Configure the run script on Jenkins

  • Configure test result reporting on Jenkins



  • Configure the JDK and Maven paths in Jenkins.
  • After configuration, click Build Now and start running. The result is as follows:



In conclusion: following the above steps we can easily complete the fully automated process of interface performance testing!

Ps: About displaying test results: 1. For example, when Jenkins used HTML Publisher to view the report, it was found that the display was not beautiful and incomplete, and many things could not be displayed. To solve this problem, you can input the following script in Jenkins system management to run and solve the problem

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP"."")Copy the code

2. Many HTML results are empty, please change the corresponding false of jmeter.property to true. 3. Add a using XSLT 2.0 dependency to POM.xml when testing reports NaN.