Jmeter+jenkins+ant automated test environment construction

Environment: Windows

1. Prepare the installation package

JDK:jdk1.8.0_191

Jmeter:apache-jmeter-5.0

ANT:apache-ant-1.10.7

Jenkins:Jenkins2.233

2. Install JDK

Download address: https://www.oracle.com/java/technologies/javase-downloads.html

After downloading, go to the next step

1. Configure environment variables, enter the system of win 10 system-advanced system settings-system properties-advanced-environment variables.

1) Add the system variable JAVA_HOME, fill in the jdk installation path


2) Add %JAVA_HOME%\bin and %JAVA_HOME%\jre\bin to the system variable PATH

insert image description here
3) Add %JAVA_HOME%\bin;%JAVA_HOME%\lib\dt.jar to the system variable classpath; (Note that there must be an English ; sign at the end)

insert image description here
4) Open the command line with cmd, enter java -version, and print out the version number to complete the installation.

3. Install Jmeter

Download link: http://jmeter.apache.org/download_jmeter.cgi

After the download is complete, unzip it directly in the directory you placed

1) Win 10 system enters the system – advanced system settings – system properties – advanced – environment variables, create a new JMETER_HOME, write the installation path


2) CLASSPATH add:

%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-2.0.jar;%ANT_HOME%\lib;

3) Add PATH: %JMETER_HOME%\bin

4) Enter the command line, enter jmeter -v, then the installation is successful

4. Install ANT

Download address: http://ant.apache.org/bindownload.cgi

After downloading, unzip it directly to the desired directory. I put jmeter and ant in the same directory

1) Configure environment variables, win 10 system to enter the system – advanced system settings – system properties – advanced – environment variables, create a new system variable ANT_HOME, the installation path of ant


2) Add CLASSPATH: %ANT_HOME%\lib;

3) Add PATH: %ANT_HOME%\bin

4) Enter ant -version on the command line, and if the version number is displayed, the installation is complete



6) Create two new folders to store html reports and jtl reports, and create a new folder to store jmx files. I created them as follows:



7) Create a new build.xml as follows, the specific modification items are marked in the code, put it in the folder where jmx is placed, and under the installation path of ant:

<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyyMMddhhmm" />
    </tstamp>
    <!-- 需要改成自己本地的 Jmeter 目录-->  
    <property name="jmeter.home" value="E:\apache-jmeter-5.0\apache-jmeter-5.0" />
    <!-- jmeter生成jtl格式的结果报告的路径--> 
    <property name="jmeter.result.jtl.dir" value="E:\apache-jmeter-5.0\resultLog\jtl" />
    <!-- jmeter生成html格式的结果报告的路径-->
    <property name="jmeter.result.html.dir" value="E:\apache-jmeter-5.0\resultLog\html" />
    <!-- 生成的报告的前缀-->  
    <property name="ReportName" value="TestReport" />
    <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
    
    <target name="run">
        <antcall target="test" />
        <antcall target="report" />
    </target>
    
    <target name="test">
        <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
        <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
             <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->
            <testplans dir="E:\apache-jmeter-5.0\JmeterTest" includes="*.jmx" />

            <property name="jmeter.save.saveservice.output_format" value="xml"/>

        </jmeter>
    </target>
    
    <path id="xslt.classpath">
        <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
        <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
    </path>
    
    <target name="report">
       <tstamp> <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>
        <xslt 
              classpathref="xslt.classpath"
              force="true"
              in="${jmeter.result.jtlName}"
              out="${jmeter.result.htmlName}"
              style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">
              <param name="dateReport" expression="${report.datestamp}"/>
       </xslt>
                <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 --> 
        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            </fileset>
        </copy>
    </target>
</project>


8) The command line enters the folder where the test jmx file is placed, executes the ant command, and the execution is successful as follows


Successfully generated html files and jtl files


The generated html report is as follows:

Here is the optimized html report, you need to download the style file: jmeter.results.shanhe.me.xsl

5. Install Jenkins

Download link: https://www.jenkins.io/download/

Download jenkins and unzip it

1) Enter the jenkins installation directory from the command line, and execute java -jar jenkins.war to start, the default port number is 8080, pay attention to whether there is a port occupied

2) Enter localhost:8080, download and install by default, create a new administrator user, and download some plug-ins by default

3) Go to the plugin download page of jenkins and download the plugins Ant Plugins, Public HTML reports, Performance Plugin


4) Enter the manage jenkins --global tool configration global tool configuration, and enter the local paths of jdk and ant


5) Create a new free-style project, and enter the number of days and numbers to keep building:


6) Configure ant and increase the build path

7) Add pulish html reports (yes, that is the plug-in that must be downloaded), the configuration is as follows, the html directory is consistent with the path of the html file in build.xml

8) Add a Publish Performance test result report, the file path fills in the jtl storage path in build.xml

9) Save and click build to build, the build is successful

10) View the HTML Report

11) View the Performance trend, you can view the jtl report



Public account fan benefits

  • Get a full set of software testing resources for free

  • Software testing interview question brushing applet is free to use

  • Free use of GPT exclusively for testers

insert image description here

Guess you like

Origin blog.csdn.net/m0_53918927/article/details/131111437