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文件,参考如下文件内容修改:

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

<project name="ant-jmeter-test" default="run" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyy-MM-dd HH-mm" />
    tstamp>
      
    <property name="jmeter.home" value="D:\apache-jmeter-4.0" />
     
    <property name="jmeter.result.jtl.dir" value="D:\接口测试\result-jtl" />
    
    <property name="jmeter.result.html.dir" value="D:\接口测试\result-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" />
    
    <path id="xslt.classpath">
        <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
        <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
    path>
    
    <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}">
             
            <testplans dir="D:\接口测试\订单服务接口" includes="*.jmx" />
            <testplans dir="D:\接口测试\资金模块微服务接口" includes="*.jmx" />
            
        jmeter>
    target>
        
    <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>
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测试报告)