Ant Jmeter Jenkins生成html测试报告

Ant配置

1、 将jmeter安装目录或者源码目录下\apache-jmeter-3.1\extras的ant-jmeter-1.1.1.jar复制到ant安装目录下apache-ant-1.10.3\lib

2、在Ant安装目录下新建build.xml文件,参考如下文件内容修改:

"1.0" encoding="UTF-8"?>

"ant-jmeter-test" default="run" basedir=".">
    
        "time" pattern="yyyy-MM-dd HH-mm" />
    </tstamp>
    <!-- 需要改成自己本地的 Jmeter 目录-->  
    "jmeter.home" value="D:\apache-jmeter-4.0" />
    <!-- jmeter生成jtl格式的结果报告的路径--> 
    "jmeter.result.jtl.dir" value="D:\接口测试\result-jtl" />
    <!-- jmeter生成html格式的结果报告的路径-->
    "jmeter.result.html.dir" value="D:\接口测试\result-report" />
    <!-- 生成的报告的前缀-->  
    "ReportName" value="TestReport-" />
    "jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
    "jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
    
    "xslt.classpath">
        dir="${jmeter.home}/lib" includes="xalan*.jar"/>
        dir="${jmeter.home}/lib" includes="serializer*.jar"/>
    </path>
    
    "run">
        "test" />
        "report" />
    </target>
    
    "test">
        "jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
    
    "${jmeter.home}" resultlog="${jmeter.result.jtlName}">
             <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->
			dir="D:\接口测试\订单服务接口" includes="*.jmx" />
			dir="D:\接口测试\资金模块微服务接口" includes="*.jmx" />
			
        </jmeter>
    </target>
        
    "report">
         "report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>
        "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}">
            dir="${jmeter.home}/extras">
                "collapse.png" />
                "expand.png" />
            </fileset>
        </copy>
    </target>
</project>

Jmeter配置

1、打开jmeter安装目录apache-jmeter-3.1\bin中的jmeter.properties,把jmeter.save.saveservice.output_format=csv 值修改为xml,即:jmeter.save.saveservice.output_format=xml

2、jmeter.properties文件中,修改如下值为true:

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
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

jenkins配置:

打开jenkins,进入插件管理,安装插件Performance Plugin、HTML Publisher plugin、Email Extension Plugin、Ant Plugin、git plugin、Github plugin等,在构建后操作选择 Groovy Postbuild ,在 Groovy Script 中输入:System.setProperty(“hudson.model.DirectoryBrowserSupport.CSP”, “”)

四、Jenkins任务配置
Ant Jmeter Jenkins生成html测试报告_第1张图片
Ant Jmeter Jenkins生成html测试报告_第2张图片

你可能感兴趣的:(jmeter,jenkins)