首先介绍一下Ant。Apache Ant,是一个将软件编译、测试、部署等步骤联系在一块儿加以自动化的一个工具,大多用于Java环境中的软件开发。由Apache软件基金会所提供。html
是的、仍是Apache家的产品,去其官网看看其简介。express
Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.apache
Ant is written in Java. Users of Ant can develop their own "antlibs" containing Ant tasks and types, and are offered a large number of ready-made commercial or open-source "antlibs".app
Ant is extremely flexible and does not impose coding conventions or directory layouts to the Java projects which adopt it as a build tool.工具
Software development projects looking for a solution combining build tool and dependency management can use Ant in combination with Apache Ivy.布局
The Apache Ant project is part of the Apache Software Foundation.测试
Apache Ant是一个Java库和命令行工具,其任务是将构建文件中描述的进程做为相互依赖的目标和扩展点。Ant的主要用途是构建Java应用程序。Ant提供了许多内置任务,容许编译,组装,测试和运行Java应用程序。Ant还能够有效地用于构建非Java应用程序,例如C或C ++应用程序。更通常地说,Ant能够用来试验任何类型的过程,能够用目标和任务来描述。flex
Ant是用Java编写的。Ant的用户能够开发本身的包含Ant任务和类型的“antlib”,并提供大量现成的商业或开源“antlibs”。ui
Ant很是灵活,而且不会将编码约定或目录布局强加给采用它做为构建工具的Java项目。编码
寻找结合构建工具和依赖管理的解决方案的软件开发项目能够将Ant与Apache Ivy结合使用。
Apache Ant项目是Apache Software Foundation的一部分。
既然也是Apache家的产品,那么也可以与Jmeter进行集成的。
来具体记一记Jmeter是如何与Ant进行集成的,然后又如何延伸至Jenkins的。
Ant的搭建环境再也不记录。
其主要的仍是有关于xml配置文件的编辑。
一、首先将${jmeter_home}\extras\ant-jmeter-1.1.1.jar,copy至{ant_home}\lib下。
二、定义build.xml文件。
<?xml version="1.0" encoding="UTF-8"?> <project name="ant-jmeter-test" default="run" basedir="."> <taskdef resource="net/sf/antcontrib/antlib.xml" /> <!--须要改为本身本地的 Jmeter 目录--> <property name="jmeter.home" value="F:\jmeter\apache-jmeter-3.2"/> <property name="report.title" value="report"/> <!-- jmeter生成jtl格式的结果报告的路径--> <property name="jmeter.result.jtl.dir" value="F:\jmeter-project\Demoproject\result\jtl"/> <!--jmeter生成html格式的结果报告的路径--> <property name="jmeter.result.html.dir" value="F:\jmeter-project\Demoproject\result\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}"> <!--脚本存放路径--> <testplans dir="F:\jmeter-project\Demoproject\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.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> </project>
其实,在${jmeter_home}\extras\下有一个build.xml的文件,不过相对来讲比较繁琐,此处是一个参照网上大神的一个精简版。须要更换的目录,代码段已经插入了相关注释。
此处是构建
F:\jmeter-project\Demoproject\Script目录下的所有.jmx文件,所以使用*.jmx
该目录下存放两个jmx脚本,一共是103个Sampler
三、进入存放build.xml的目录,执行ant命令进行构建。
四、
能够看到,已经构建成功,至日志保存目录进行查看。
这个是Ant构建生成的html报告。
固然报告的模板也是可以进行设计。该处使用的是${jmeter_home}\extras目录下的jmeter-results-report_21.xsl。
OK、再集成至Jenkins又当如何集成呢?
上篇是经过Jmeter的NO-GUI方式直接以Jenkins进行执行dos命令行命令,构建。
使用Ant的话更为简洁。
所需插件:Invoke Ant
填写参数Targets 、 Build File
Targets为build.xml文件中的target name。
Bulid File为build.xml文件在本地的路径
至于构建后的操做:Publish HTML Reports主要是用做显示报告。
OK,开始构建。
构建成功、至本地查看报告生成或者Jenkins面板均可以。
报告文件已生成。
咱们做为测试人员,使用Ant无非就是批量执行jmeter的脚本文件,再使用Jenkins进行自动构建(定时自动构建),不就实现自动化了么,平常的回归,冒烟等等皆可知足。