首先,jmeter安装就不说了,然后我们直接说ant
1、首先下载apache-ant-1.9.14-bin.zip的安装包,然后解压配置环境变量如图:
配置完之后再dos窗口下输入ant -version ,展示如下图则说明配置成功
2、修改jmeter bin 文件夹下jmeter.properties文件内容
编辑jmeter配置文件jmeter.properties,配置输出格式为xml,jmeter默认的输出格式为csv;
jmeter.save.saveservice.output_format=xml
3、ant依赖包配置
把D:\jemeter\apache-jmeter-5.1.1\extras\ant-jmeter-1.1.1.jar包放到ant_home\lib 目录下
4、jmeter下文件夹建立,存放脚本,测试报告。
在D:\jemeter\apache-jmeter-5.1.1下建立demo 文件夹,测试脚本直接放到demo 文件夹下,在demo 下建立resultLog,在resultLog文件夹下建立html文件夹和jtl文件夹,这些个文件夹在下面build.xml 配置文件里我们会用到。
5、build.xml文件的配置
在ant_home\bin目录下新建build.xml 文件,文件内容范模板如下
模板一:
<?xml version="1.0" encoding="UTF8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- (1)需要改成自己本地的 Jmeter 目录-->
<property name="jmeter.home" value="D:\jemeter\apache-jmeter-5.1.1"/>
<property name="report.title" value="report"/>
<!-- (2)jmeter生成jtl格式的结果报告的路径-->
<property name="jmeter.result.jtl.dir" value="D:\jemeter\apache-jmeter-5.1.1\demo\resultLog\jtl"/>
<!-- (3)jmeter生成html格式的结果报告的路径-->
<property name="jmeter.result.html.dir" value="D:\jemeter\apache-jmeter-5.1.1\demo\resultLog\html"/>
<!-- 生成的报告的前缀 -->
<property name="ReportName" value="TestReport"/>
<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}.jtl"/>
<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}.html"/>
<target name="run">
<antcall target="test"/>
<antcall target="report"/>
<!--antcall target="mail"/-->
</target>
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<!-- (4)build.xml的存放的路径-->
<testplans dir="D:\jemeter\apache-jmeter-5.1.1\demo" 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-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>
<path id="lib_classpath">
<fileset dir="${basedir}/">
<include name="mail*.jar" />
<include name="activation*.jar" />
<include name="commons-email*.jar" />
<include name="ant-contrib*.jar" />
</fileset>
</path>
<!--target name="mail">
<for list="hanxm@thunisoft.com" param="tmp" >
<sequential>
<echo>message @{tmp}</echo>
<mail mailhost="smtp.thunisoft.com" mailport="25" ssl="false" subject="ant mail" messagemimetype="text/html" user="zhangjn" password="*******" tolist="@{tmp}">
<from address="zhangjn@thunisoft.com" />
<fileset dir="${jmeter.result.html.dir}">
<include name="*.html" />
<include name="*.png" />
</fileset>
<message>支持多人同时发邮件!!<br /><br /></message>
</mail>
</sequential>
</for>
</target-->
</project>
1.修改build.xml中的(1)(2)(3)(4)的路径修改为自己的响应的路径
2.将build.xml中的第42行
style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
拷贝以下内容将这个路径下的jmeter-results-detail-report_21.xsl文件覆盖,这个文件说明了xsl文件装换为html文件的一些规则
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Stylesheet for processing 2.1 output format test result files
To uses this directly in a browser, add the following to the JTL file as li