一、Jmeter安装
1.安装JDK,并配置环境变量
2.安装Jmeter
具体步骤参考:https://www.jianshu.com/p/57eabab77e83
二、下载配置ant(可跳过,主要用来验证本地ant是否可成功调用Jmeter执行)
1.下载安装ant:apache-ant-1.9.14-bin.zip,解压即可。
https://ant.apache.org/bindownload.cgi
2.配置环境变量
ANT_HOME D:\test_tool\apache-ant-1.9.14
path %ANT_HOME%\bin
3.验证ant是否安装成功
cmd打开 输入ant执行:ant -version

4.将\apache-jmeter-5.0\extras\ant-jmeter-1.1.1.jar复制到ant的lib目录下

三、下载xsltproc,将jtl格式的文件转为html。
步骤(前4步即可):https://www.cnblogs.com/MasterMonkInTemple/p/7874533.html
四、通过ant调用Jmeter执行脚本。(可跳过,主要用来验证本地ant是否可成功调用Jmeter执行)
1.建立build.xml
**********************************************************build.xml*********************************************************
<?xml version="1.0" encoding="UTF-8"?>
<project name="test_zcj" default="run" basedir=".">
<tstamp>
<format property="time" pattern="yyyyMMddhhmm" />
</tstamp>
<!-- 需要改成自己本地的 Jmeter 目录-->
<property name="jmeter.home" value="D:\test_tool\apache-jmeter-5.0" />
<!-- jmeter生成jtl格式的结果报告的路径-->
<property name="jmeter.result.jtl.dir" value="D:\test_tool\apache-jmeter-5.0\test_zcj\report\jtl" />
<!-- jmeter生成html格式的结果报告的路径-->
<property name="jmeter.result.html.dir" value="D:\test_tool\apache-jmeter-5.0\test_zcj\report\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:\test_tool\Jmeter" includes="HTTP请求.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-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>
</project>
***************************************************build.xml**********************************************************
参照注释修改Jmeter及执行脚本等一些文件的路径即可。
2.进入build.xml路径,执行

3.执行成功,查看报告。


五、安装Jenkins
可参考资料:https://www.cnblogs.com/wuxunyan/p/9592953.html
必备插件:HTML Publisher、ant
***遇到的坑***
1.首次登录后会提示注册用户,注册后再次登录admin,报错密码不正确(其实输入的就是当时设置的),

解决:输入首次登录系统预设的密码,然后退出,再用admin/设置的密码即可登录。

六、配置Jenkins
1、http://localhost:8080/jenkins,启动,并创建项目

选择第一个自由风格,然后点击OK按钮

2. 丢弃就的构建:保持构建天数2,保持构建的最大个数 5(根据需要)

3.构建:配置ant,增加build路径。

点击高级


4.配置测试报告
构建后操作:增加构建后步骤 publish html reports

配置html报告路径,点击保存,报告配置完成。

七、执行项目
1.点击立即构建

2.构建完成后,如果失败可查看运行日志,成功后可查看报告。



网友评论