Installation and use of automated testing jmeter+ant+Jenkins environment

Table of contents

1.1 Install jmeter

Configure environment variables

Installation verification

1.2 Install jdk

1.3 Install Ant

1.4 Test report generation

1.5 Configure Jenkins and build continuous integration


Foreword: Automated testing jmeter+ant+Jenkins mainly uses jmeter to write test scripts, uses the ant tool to control script case execution and output test reports, and Jenkins does scheduled builds and continuous integration.

1.1 Install jmeter

Download the jmeter compressed package and decompress it directly.

Configure environment variables

 

JMETER_HOME 为 jemter安装路径;

 CLASSPATH为 %JMETER_HOME%\lib;

 PATH为%JMETER_HOME%\bin;
Installation verification

Enter jmeter -v in the command window and press Enter. If the jmeter version appears, the configuration is successful.

 

You can directly enter jmeter in the command window and press Enter to start jmeter; you can also start jmeter between double-clicking .

 Basic use of jmeter

Create a new thread group in jmeter and add an http request

 Fill in the interface data in the new HTTP request

Add the response assertion in the assertion and the view result tree in the listener to the http request, and you can view the interface request results.

 

1.2 Install jdk

Both Jmeter and Jenkins are tools that run based on Java and require a Java environment to be installed. Download the installation package (I am using jdk1.8 version, download it yourself)

 Configure environment variables

JAVA_HOME 为 C:\Program Files\Java\jdk1.8.0_131 (注意:java我是默认装的C盘)

CLASSPATH为  .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;

PATH为  %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

Installation verification

Enter java -version in the command window and press Enter. If the java version appears, the configuration is successful.

 

1.3 Install Ant

Installation package download

The download address is http://ant.apache.org/bindownload.cgi. After downloading, unzip it to the specified location. I put it in the same location as jmeter.

 

 

 

Configure environment variables

   

ANT_HOME 为 ant解压位置

CLASSPATH为 %ANT_HOME%\lib;

PATH为%ANT_HOME%\bin;

Installation verification

To verify the installation result, enter ant -v on the command line. If the version information appears, the installation is successful.

 

1.4 Test report generation

Configuration library file

Copy the ant-jmeter-1.1.1.jar file in the jmeter extras directory to the lib folder in the ant installation directory

 

Configure the ant compilation file build.xml

Modify the following documents according to the actual situation:

 

 

Configure jmeter.propertise document

Find the jmeter.properties document, open the document in the jmeter/bin directory, edit it, and modify the jmeter report output format to xml:

Change jmeter.save.saveservice.output_format=csv to jmeter.save.saveservice.output_format=xml, and remove the previous comment symbol#

 

 

Verify configuration and execute build tests

Save the previous jmeter script and place the build.xml configuration file in the same directory as the test script. My directory is as follows:

 

Execute tests

Open the command window in the directory where build.xml is located (press the shift key in the blank space and then right-click),

Or use the command line to cd to the directory where the build.xml file is located, enter ant run and press Enter to execute the test.

 

 

View test report

Check whether there are jtl and html result reports under the report output storage path. The storage path is also in the build document.

 

 Optimize test report

(1) Download the optimization template jmeter-results-shanhe-me.xsl and copy it to the extras directory of jmeter. Download address: jmeter.results.shanhe.me.xsl icon-default.png?t=N5K3http://shanhe.me/download.php?file= jmeter.results.shanhe.me.xsl

 

(2) Set the content to be output in the test output report: Also in jmeter.properties, set the content to be output to true, and remove the comment symbol # in front. Here, set everything to true → save

 

 

(3) Set the report template of the build file to the optimized template jmeter-results-shanhe-me.xsl

 

(4) Optimized test report

 

 

1.5 Configure Jenkins and build continuous integration

Jenkins can use Jenkins on 192.168.2.211 and create a new Jenkins node using local resources and jemter+ant environment. You can also install local Jenkins yourself

Access the jenkins server:

Enter in the browser: http://  http://192.168.2.211:8081 , log in

jenkins configure remote node

Open Jenkins and click "Build Execution Status"

Select the new node, enter the node name, and configure the node

 

Open a Windows window, go to the directory where agent.jar was just placed, and execute the start node command.

Open Jenkins, configure the user name, password and plug-in. Here you need to configure the invoke ant plug-in and the plug-in displayed in the HTML test report . 192.168.2.211 The Jenkins plug-ins on the Linux environment have been installed and there is no need to install them again.

( 1 ) In System Management-System Settings in Jenkins, configure jdk and Ant variables

 

Create a new project and configure it

 

 

 

Points to note :

( 1 ) When ant builds a project, the build.xml in the workspace in Jenkins is executed by default . If there is no build.xml in the workspace, the build will report an error. My approach is to place all the build.xml files in the workspace directory. You can modify the path to run the script and the path to store the report in the build.xml file to specify the path to run the script and store the report .

( 2 ) The build variables in the new project must use the variable names of the local ant and jdk paths set in the "Global Tool Configuration".

 Configure Publish HTML reports to view and generate HTML reports directly in Jenkins

Note: The value of Index page[s]: is consistent with the test report name set in build.xml. The name input here supports fuzzy matching "*" .

 

Script configuration is completed.

Configure synchronization of Jenkins build status and script execution status

Because the Jenkins build status and script execution are not connected, the Jenkins build status of the use case where the script fails to execute is also built successfully, so you need to add a Windows batch command to process the script to make the Jenkins build status consistent with the script execution status.

Add the processing Windows batch command writing command in the added build step:

#Enter the file directory where the jtl directory is stored and execute #

#The following is based on whether there is <failure>true in *.jtl to determine whether there is a jmeter failure script. If there is, the build fails, otherwise the build is successful.

findstr /i "<failure>true" *.jtl#“*”表示匹配文件下所有jtl文件

if NOT %ERRORLEVEl% == 0 (

echo "无失败用例" && exit 0

)else (

echo "有失败用例" && exit 1

 

On the project homepage, click Build Now to execute the test

 

Continue to build and it is basically completed. Open the test report storage path and you will see the newly generated report document.

Guess you like

Origin blog.csdn.net/q_syh/article/details/131517505