The latest released csdn most cattle and most complete JMeter+Ant+Jenkins interface automated testing framework (Windows)

1: Introduction

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

Two: jmeter+JDK installation

If you don't know how to install it, click here    to get a full set of software testing (automated testing) video data for free (note "csdn000") to receive the installation tutorial and installation package

Three: Ant download/install

Download the installation package to the specified location, and then extract the apache-ant-1.10.7.zip to the current directory. (Download address Apache Ant - Binary Distributions )

Configure Ant environment variables

1). New ANT_HOME: the value is the Ant installation path (eg after decompression: D:\jmeter\jmeter-ant\apache-ant-1.10.7)
2). After the PATH system variable, add: %ANT_HOME%\bin
3) Add to the .CLASSPATH system variable: %ANT_HOME%\lib

After the settings are saved, enter the cmd window, enter ant -v, and the installation is successful if the version information appears.

Ant configures JMeter, uses ant to build and run Jmeter, and generates jtl, html reports
1). Copy the ant-jmeter-1.1.1.jar file in the jmeter extras directory to the lib folder in the ant installation directory.
2). jmeter saves the file in .csv format by default, so we need to modify the content of the jmeter/bin/jmeter.properties file, change jmeter.save.saveservice.output_format=csv to jmeter.save.saveservice.output_format=xml, and Remove the preceding comment symbol#


Optimize the test report Download the optimization template, download jmeter-results-shanhe-me.xsl, and put it in the extras directory of jmeter (download address: jmeter.results.shanhe.me.xsl )
Modify the jmeter/bin/jmeter.properties file, Set the content to be output to true, and remove the preceding comment symbol #, and save. In this way, after the script is executed, the results will be saved in the .jtl file (increase the content of the test report)

#
jmeter.save.saveservice.data_type=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
jmeter.save.saveservice.response_data=true
# Save ResponseData for failed samples
jmeter.save.saveservice.response_data.on_error=true
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=true
jmeter.save.saveservice.assertions=true
jmeter.save.saveservice.latency=true
# Only available with HttpClient4
jmeter.save.saveservice.connect_time=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.encoding=true
jmeter.save.saveservice.bytes=true
# Only available with HttpClient4
jmeter.save.saveservice.sent_bytes=true
jmeter.save.saveservice.url=true
jmeter.save.saveservice.filename=true
jmeter.save.saveservice.hostname=true
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.sample_count=true
jmeter.save.saveservice.idle_time=true

3). Create a new folder anywhere, and then create a new jmeter_report folder, script folder, and build.xml file under the folder respectively
(configure the ant compiled file build.xml (Note: There is also a build under the extras file of jmeter). .xml document, don't use this document to change, it's two different things, the build document here is created by yourself)


4). Create a new build.xml file and modify the contents of the document

<?xml version="1.0" encoding="utf8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyyMMddHHmm" />
    </tstamp>
    <!-- 需要改成自己本地的jmeter目录-->
    <property name="jmeter.home" value="D:\jmeter_ant\apache-jmeter-5.4.3" />
    <!-- jmeter生成的jtl格式的结果报告的路径-->
    <property name="jmeter.result.jtl.dir" value="D:\jmeter_testcase\jmeter_report\jtl" />
    <!-- jmeter生成的html格式的结果报告的路径-->
    <property name="jmeter.result.html.dir" value="D:\jmeter_testcase\jmeter_report\html" />
    <!-- ʺ生成的报告的前缀-->
    <property name="ReportName" value="TestReport_" />
    <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/TestReport_${time}.jtl" />
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${time}_SummaryReport.html" />
    <property name="jmeter.detail.result.jtlName" value="${jmeter.result.jtl.dir}/TestReport_${time}.jtl" />
    <property name="jmeter.detail.result.htmlName" value="${jmeter.result.html.dir}/${time}_DetailReport.html" />
    <target name="run">
        <antcall target="test" />
        <antcall target="report" />
        <!--<antcall target="sendmail" />-->
    </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="D:\jmeter_testcase\script" 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.detail.result.jtlName}" out="${jmeter.detail.result.htmlName}" style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">
            <param name="dateReport" expression="${report.datestamp}"/>
        </xslt>
        <xslt classpathref="xslt.classpath" force="true" in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.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>
    <!-- 	<target name="sendmail">  
<mail mailhost="smtp.exmail.qq.com" mailport="465" ssl="true" user="[email protected]" password="GHtMMpSB5xpytzyM" subject="预付卡前置接口测试报告" from="[email protected]">  
<to address="[email protected]"/>  
<message>详细报告请查看附件</message>  
<attachments>  
<fileset dir="${jmeter.result.html.dir}">   
<include name="${ReportName}${time}.html"/>  
</fileset>   
</attachments>  
</mail>  
</target>  -->
</project>

Verify configuration

Put the previous Jmeter script in the same directory as the build.xml configuration file. 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 cd to the directory where the build.xml file is located, enter ant run and press Enter to execute the test

View test report


General report

Detail report

   Click me to get a full set of software testing (automated testing) video materials for free (note "csdn000")

Four: Install Jenkins and configure it, build continuous integration

Introduction: Jenkins is an open source software project. It is a continuous integration tool developed based on Java. It is used to monitor continuous repetitive work and make continuous software integration possible.
1). Download the Jenkins installation package, download address: Jenkins download and deployment (Before installing Jenkins, make sure your computer has been configured with JDK)


2). Double-click the downloaded jenkins.msi to install (fool)
3). After installation, it will automatically open the browser and open the address: localhost:8080
4). Enter the password according to the prompted path


5).Choose plug-in installation, or install manually. Mainly install HTML Publisher Plugin and Ant In Workspace
6). After installing the plugin, create a new user


7). In Jenkins system management - system settings, configure jdk and Ant.



8). Create a new project



The script configuration is complete, click Apply.
Go to the project home page, click Build to generate a report

    Click me to get a full set of software testing (automated testing) video materials for free (note "csdn000")



 

Guess you like

Origin blog.csdn.net/csdnchengxi/article/details/123737111