JMeter接口测试实践(3)

六、优化测试报告

○ 修改jmeter.properties文件,打开一些输出内容开关

wps6CCB.tmp

指定测试报告的输出模板,具体参考

build.xml:

<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
   
     
   
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<projectname="ant-jmeter" default="all">
    <description>

        Sample build file for use with ant-jmeter.jar
        See

    To run a test and create the output report:
        ant -Dtest=script

    To run a test only:
        ant -Dtest=script run

    To run report on existing test output
        ant -Dtest=script report

    The "script" parameter is the name of the script without the .jmx suffix.

    Additional options:
        -Dshow-data=y - include response data in Failure Details
        -Dtestpath=xyz - path to test file(s) (default user.dir).
                        N.B. Ant interprets relative paths against the build file
        -Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)
        -Dreport.title="My Report" - title for html report (default is 'Load Test Results')

        Deprecated:
        -Dformat=2.0 - use version 2.0 JTL files rather than 2.1

   
</description>
   
    <!-- <property value="${user.dir}"/>-->
    <propertyname="testpath" value="C:\apache-jmeter-2.12\testcase" />
    <propertyname="jmeter.home" value="${basedir}/.."/>
    <propertyname="report.title" value="Load Test Results"/>
   
    <!-- Name of test (without .jmx)-->
    <propertyname="test" value="Test"/>
   
    <!-- Should report include response data for failures?-->
    <propertyname="show-data" value="n"/>

    <propertyname="format" value="2.1"/>
   
    <conditionproperty="style_version" value="">
        <equalsarg1="${format}" arg2="2.0"/>
    </condition>

    <conditionproperty="style_version" value="_21">
        <equalsarg1="${format}" arg2="2.1"/>
    </condition>

    <conditionproperty="funcMode">
        <equalsarg1="${show-data}" arg2="y"/>
    </condition>
   
    <conditionproperty="funcMode" value="false">
      <not>
        <equalsarg1="${show-data}" arg2="y"/>
      </not>
    </condition>

    <!-- Allow jar to be picked up locally-->
    <pathid="jmeter.classpath">
        <filesetdir="${basedir}">
          <includename="ant-jmeter*.jar"/>
        </fileset>
    </path>

    <taskdef
       
name="jmeter"
        classpathref
="jmeter.classpath"
        classname
="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
   
    <targetname="all" depends="run,report"/>

    <targetname="run">
        <echo>funcMode = ${funcMode}</echo>
        <deletefile="${testpath}/${test}.html"/>
        <jmeter
           
jmeterhome="${jmeter.home}"
            testplan
="${testpath}/*.jmx"
            resultlog
="${testpath}/${test}.jtl">
        <!--
            <jvmarg value="-Xincgc"/>
            <jvmarg value="-Xmx128m"/>
            <jvmarg value="-Dproperty=value"/>
            <jmeterarg value="-qextra.properties"/>
       
-->
            <!-- Force suitable defaults-->
            <propertyname="jmeter.save.saveservice.response_data" value="true"/>
            <propertyname="jmeter.save.saveservice.samplerData" value="true"/>
            <propertyname="jmeter.save.saveservice.responseHeaders" value="true"/>
            <propertyname="jmeter.save.saveservice.requestHeaders" value="true"/>
            <propertyname="jmeter.save.saveservice.encoding" value="true"/>
            <propertyname="jmeter.save.saveservice.url" value="true"/>
            <propertyname="jmeter.save.saveservice.filename" value="true"/>
            <propertyname="jmeter.save.saveservice.hostname" value="true"/>
            <propertyname="jmeter.save.saveservice.thread_counts" value="true"/>
            <propertyname="jmeter.save.saveservice.sample_count" value="true"/>
            <propertyname="jmeter.save.saveservice.idle_time" value="true"/>
            <propertyname="jmeter.save.saveservice.output_format" value="xml"/>
            <propertyname="jmeter.save.saveservice.assertion_results" value="all"/>
            <propertyname="jmeter.save.saveservice.bytes" value="true"/>
            <propertyname="file_format.testlog" value="${format}"/>
            <propertyname="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>
        </jmeter>
    </target>

    <propertyname="lib.dir" value="${jmeter.home}/lib"/>

    <!-- Use xalan copy from JMeter lib directory to ensure consistent processing with Java 1.4+-->
    <pathid="xslt.classpath">
        <filesetdir="${lib.dir}" includes="xalan*.jar"/>
        <filesetdir="${lib.dir}" includes="serializer*.jar"/>
    </path>

    <targetname="report" depends="xslt-report,copy-images">
        <echo>Report generated at ${report.datestamp}</echo>
    </target>

    <targetname="xslt-report" depends="_message_xalan">
        <tstamp><formatproperty="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
        <xslt
           
classpathref="xslt.classpath"
            force
="true"
            in
="${testpath}/${test}.jtl"
            out
="${testpath}/${test}.html"
            style
="C:\apache-jmeter-2.12\extras\jmeter-results-shanhe-me.xsl">
            <paramname="showData" expression="${show-data}"/>
            <paramname="titleReport" expression="${report.title}"/>
            <paramname="dateReport" expression="${report.datestamp}"/>
        </xslt>
    </target>

    <!-- Copy report images if needed-->
    <targetname="copy-images" depends="verify-images" unless="samepath">
        <copyfile="${basedir}/expand.png" tofile="${testpath}/expand.png"/>
        <copyfile="${basedir}/collapse.png" tofile="${testpath}/collapse.png"/>
    </target>

    <targetname="verify-images">
        <conditionproperty="samepath">
                <equalsarg1="${testpath}" arg2="${basedir}" />
        </condition>
    </target>

    <!-- Check that the xalan libraries are present-->
    <conditionproperty="xalan.present">
          <and>
              <!-- No need to check all jars; just check a few-->
            <availableclasspathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
            <availableclasspathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
          </and>
    </condition>

    <targetname="_message_xalan" unless="xalan.present">
          <echo>Cannot find all xalan and/or serialiser jars</echo>
        <echo>The XSLT formatting may not work correctly.</echo>
        <echo>Check you have xalan and serializer jars in ${lib.dir}</echo>
    </target>


</project>

jmeter-result-shanhe-me.xsl:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a85a578328a53ee4b8c835cfe854658a.html