ANT use

Outline

  ant is a software compilation, testing, deployment and other steps be automated contact with a tool, mostly for Java software development environment.
  In the Jmeter jmx file generated with the use, ant will complete the implementation plan and generate jtl jmx file, and will be viewed as jtl files into html pages.
  It can also be used in conjunction with Jenkins.
  Advantages: cross-platform, simple operation, easy maintenance, ease of integration.

 

  Dependent
  upon the use of ant make sure you have installed java jdk, because of the need to rely on the use of ant java environment.
  And the need to configure the java environment variable.

 

installation

  Into the apache-ant's official website and download the zip package. https://ant.apache.org/bindownload.cgi

 

  Unzip the downloaded zip.

  After extracting ant bin directory is the entry point for running the program, if the ant is useless to configure the environment variables, run the bat program in the bin directory, you can achieve the same purpose build task.

 

  ANT environment variable configuration

  In order to facilitate the use of ant environmental variable configuration.
  In My Computer -> Right Properties -> Advanced System Configuration -> Environment Variables -> System Variables add ant path.


  New System Variable ANT_HOME = C: \ apache-ant-1.9.9

 

 

  To the last position at the contents of the PATH environment variable:

  ;% ANT_HOME% \ bin Note the semicolon in front.

 

 

   Check the installation is successful

  Ant -version used to verify the configuration

 

 

use

  Set up

  jmeter默认保存的是.csv格式的文件,所以需要设置 bin/jmeter.properties 文件内容,将 jmeter.save.saveservice.output_format=csv 取消注释,并且将csv修改为xml;

 

  将apache-jmeter-5.1.1\extras\ant-jmeter-1.1.1.jar拷贝到apache-ant-1.9.9\lib目录下;

  这样ant运行时才能找到 "org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" 这个类,从而成功触发JMeter脚本。

 

  新建 build.xml

在存放Jmeter导出的 jmx 目录下,新建build.xml文件,并且编辑内容如下:
在ant运行时会在当前目录下寻找build.xml文件,所以在运行时要确保 build.xml 在当前目录下。

<?xml version="1.0" encoding="utf-8"?>
<project name="Ant-Jmeter-Test" default="all" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyyMMddhhmm" />
    </tstamp>
    <!-- 需要改成自己本地的 Jmeter 目录-->
    <property name="jmeter.home" value="F:\yang\apache-jmeter-5.1.1" />
    <!-- jmeter生成jtl格式的结果报告的路径-->
    <property name="jmeter.result.jtl.dir" value="F:\yang\apache-jmeter-5.1.1\report" />
    <!-- jmeter生成html格式的结果报告的路径-->
    <property name="jmeter.result.html.dir" value="F:\yang\apache-jmeter-5.1.1\report" />
    <!-- 生成的报告的前缀 -->
    <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="all">
        <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="F:\yang\apache-jmeter-5.1.1\case" includes="*.jmx" />
        </jmeter>
    </target>
    <target name="report">
        <xslt in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" />
        <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->
        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            </fileset>
        </copy>
    </target>

</project>

  

  如果使用上面 build.xml 内容则需要修改四个地方

   修改内容如下图

 

  还可以修改报告的名称,如下图标记的地方为测试报告的名称

 

  ant 运行

  进入build.xml 所在的目录,在命令行中使用 ant 命令进行运行

 

 

  进入report的 html 目录下查看生成结果

 

  打开 html 报告


  但是时间显示为NaN

  需要从Jmeter 的 lib 中将 xalan-2.7.2.jar 和 serializer-2.7.2.jar 两个包 copy到 Ant 的 lib 目录下
  重新运行 ant 命令生成报告,结果如下

 

 

HTML 报告强化

  下载 jmeter.results.shanhe.me.xsl 文件

  下载地址: https://pan.baidu.com/s/1MJb3ctyEHS3eWwP_AVZbzg

  下载后将文件放在...\apache-jmeter-5.1.1\extras 目录下

  修改 build.xml 中 对应 style 的值,替换成下载的文件名,如下图


  重新运行 ant 命令生成报告,结果如下

 

  比起上个报告,多了好多参数

Guess you like

Origin www.cnblogs.com/tynam/p/11804318.html
ANT
ANT