Background:
First use JMeter to record or write performance test scripts, with Maven to add dependencies, the performance test code submitted to GitHub, in Jenkins configuration git download performance test code, configure run scripts and test reports, configuration Run failed automatic email notification, This allows the job configuration of the performance test to complete. Next, the job of the performance test is configured as the downstream job of the development job, and once the development has a new code submitted to run the development of its own job, it will automatically trigger the job of our performance test. This allows us to realize the full automation of the interface performance test, we only need to focus on the test failed mail!
1 Environment Construction
- Download install JDK &eclipse.
- Download and install Jenkins.
- Download maven and unzip it.
- Download JMeter and unzip.
2 Preparing the script for the performance test
- Start JMeter (double-click the Bin\jmeter.bat in the JMeter decompression directory).
- Write test cases with JMeter and export (recommended).
- Or you can record the script with JMeter, make sure to export after running through.
- Of course you can choose to record the script with Badboy, make sure to export after running through.
3 creating MAVEN project for a performance test 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>PerformanceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PerformanceTest</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>
4 Run the performance test script in eclipse
- Select project for the performance test right-click, then select Run as-maven build in the drop-down box, then write verify on the goals of the popup dialog box, Hou Click Run (for example).
- After running, there will be test results files such as
5 Run the Performance test script in Jenkins and configure the test results
- Install the following plugins on Jenkins:
Maven Integration plugin maven for Jenkins to create a MAVEN job
Git plugin, a code for downloading performance tests from GitHub;
Performance plugin, used to display performance reports;
HTML Publisher Plugin, a report that displays test results for related interfaces.
- Create a MAVEN job in Jenkins
- Configure the run script on Jenkins
- Configure the test results report on Jenkins
- Configure the JDK and MAVEN paths in Jenkins.
- Once configured, click Build now to run and run the results such as:
In short: According to the above steps we can easily complete the interface performance testing of the automatic process!
Ps:
About displaying test results:
1. In the case of Jenkins using HTML Publisher to view the report, found that the display is not beautiful, not the whole phenomenon, a lot of things can not be displayed,
Solving this problem can be solved by entering the following script in Jenkins System management.
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
2.html results A lot of empty, please change the corresponding jmeter.property false to true.
3. The test report appears nan Please add the Using XSLT 2.0 dependency in the Pom.xml.
4. Run in Eclipse if "*.loadtest.xls" is not found, modify this file name to the XSL file name that you use
5. Thanks to the original author's excellent tutorial, original: 77963931
Jeakins+maven+jmeter Build Performance test automation (run in Eclipse if "*.loadtest.xls" is not found, modify the file name to the XSL file name that you use)