Build jmeter+ant+jenkins to realize interface automation testing framework

General idea: Jmeter can do interface testing and stress testing , and it is open source software; Ant is a Java -based construction tool that completes script execution and collects results to generate reports, which can be cross-platform; Jenkins is a continuous integration tool. Combining these three can build a set of continuous construction environment for Web HTTP interface testing, and realize interface automation testing. The PC system is Windows .

1. Install jmeter

1.1. Download the installation package (skip the process, find the installation package by yourself, and install it in any directory)

1.2. Configure environment variables

      JMETER_HOME is the jemter installation path;

  CLASSPATH为 %JMETER_HOME%\lib;

  PATH is %JMETER_HOME%\bin;

1.3. 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 clicking the jmeter.bat file

1.4. Debug an interface on jmeter (if there are multiple interfaces, just add them according to the jmeter method)

2. Install jdk

2.1. Download the installation package (I am using jdk1.8 version, download it by myself)

2.2, configure environment variables

      JAVA_HOME is C:\Program Files (x86)\Java\jdk1.8.0_171 (Note: java is installed on the C drive by default)

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

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

2.3. Installation verification

Enter java -version in the command window and press Enter, if the java version appears, it means the configuration is successful

3. Install Ant

3.1. Download the installation package

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

 

3.2, configure environment variables

      ANT_HOME is the decompression location of ant

  CLASSPATH为 %ANT_HOME%\lib;

  PATH is %ANT_HOME%\bin;

3.3. Installation Verification

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

4. Ant configures Jmeter: use the ant build command to mobilize and execute the jmeter interface test and generate a test report     

4.1. 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

4.2. Configure ant's compiled file build.xml

Create a new txt file, and rename this file to build.xml, and modify the content in the document

Note: There is also a build.xml document under the extras file of jmeter. Do not use this document to modify it. It is two different things. The build document here is created by yourself.

   The tab key cannot exist in the code, otherwise the compilation will fail, and the script to be executed must also be specified, otherwise there will be problems. I just stepped on the pit here and changed it for a long time. . . .

Modify the following documents according to the actual situation:

 

4.4. Configure jmeter.propertise document

Find the jmeter.properties document, open the document and edit it in the jmeter/bin directory, 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#

 

4.5. Verify the configuration and execute the build test

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

4.5. Execute the test

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

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

4.6 View test report

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

 

Open the html document, the test result shows the result parameters such as the name of the executed use case, the success rate, and the execution time of the use case

Is this result not very intuitive, because the test report information obtained by using the test report that comes with jmeter is not very complete. Let me talk about how to optimize the test report

 4.7. Optimize test report

(1) Download the optimized template jmeter-results-shanhe-me.xsl, and copy it to the extras directory of jmeter

    Download address: 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 previous comment symbol #, set all to true → save

 

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

 

(4) Use ant to build the test again and view the optimized test report

 

5. Configure Jenkins and build continuous integration

5.1. Download the installation package (the installation process is omitted)

5.2, configure environment variables

JENKINS_HOME 为 C:\Program Files (x86)\Jenkins

5.3. Start Jenkins

Enter in the browser: http://127.0.0.1:8080/, open jenkins, configure the user name, password and plug-in, here you need to configure the invoke ant plug-in, the plug-in displayed by the HTML test report

(1) Install HTML Publisher Plugin and Ant In Workspace in Jenkins creation management

(2) In Jenkins System Management - System Settings, configure jdk and Ant

5.4. Create and configure a project

Note: Ant builds the project. By default, the script under the workspace in Jenkins is executed. If there is no script under the workspace, the build will be fine. My approach is to place both the script and the build.xml file under the workspace directory.

Note: The value of Index page[s]: (TestReport.html) is consistent with the name of the test report set in build.xml, otherwise the test report cannot be viewed in Jenkins.

The script configuration is complete.

5.5. On the project home page, click Build Now to execute the test

Continue to build and basically complete, open the test report storage path and you will see the newly generated report document.

Friends who are doing the test can come in and communicate. The group has compiled a lot of learning materials and interview questions, project resumes, etc....

Guess you like

Origin blog.csdn.net/m0_68405758/article/details/131276867