-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.xml
More file actions
182 lines (157 loc) · 8.35 KB
/
build.xml
File metadata and controls
182 lines (157 loc) · 8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?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
http://www.apache.org/licenses/LICENSE-2.0
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.
-->
<project name="ant-jmeter" default="all">
<description>
Sample build file for use with ant-jmeter.jar
See http://www.programmerplanet.org/pages/projects/jmeter-ant-task.php
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')
</description>
<!--默认的用户目录,也就是build.xml所在的目录-->
<property name="testpath" value="${user.dir}"/>
<!--设置为客户机的JMeter根目录-->
<property name="jmeter.home" value="/Users/ericzhang/Applications/apache-jmeter-3.2"/>
<!--测试项目的title,可以任意设置value-->
<property name="report.title" value="GITHUB INTERFACE TEST"/>
<!-- Name of test (without .jmx) -->
<property name="test" value="GitHubInterfaceTest"/>
<!-- Should report include response data for failures? -->
<!--如果希望在测试报告输出失败用例的响应数据,可以将该值设置为"y", 针对请求本身的失败-->
<property name="show-data" value="y"/>
<property name="format" value="2.1"/>
<condition property="style_version" value="_21">
<equals arg1="${format}" arg2="2.1"/>
</condition>
<condition property="funcMode">
<equals arg1="${show-data}" arg2="y"/>
</condition>
<condition property="funcMode" value="false">
<not>
<equals arg1="${show-data}" arg2="y"/>
</not>
</condition>
<!-- Allow jar to be picked up locally -->
<path id="jmeter.classpath">
<fileset dir="${basedir}">
<include name="ant-jmeter*.jar"/>
</fileset>
</path>
<taskdef
name="jmeter"
classpathref="jmeter.classpath"
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<!--项目从这里开始执行, all任务依赖 run 和 report 两个任务-->
<target name="all" depends="run,report,sendmail"/>
<!--这是run任务-->
<target name="run">
<!--控制台输出-->
<echo>funcMode = ${funcMode}</echo>
<!--执行前删除已有测试报告的操作,因为我们后面设置的报告名称和这里不一致,所以该语句无效-->
<delete file="${testpath}/${test}.html"/>
<!--因我的项目希望每次执行的时候将原来的JMeterResults.jtl测试数据删除重新生成,所以在执行测试前删除该文件-->
<delete file="${testpath}/result/test_data/${test}.jtl"/>
<!-- 因为我的项目希望执行的是工程目录jmx下的所有脚本,所以要使用testpalans, 删除testplan ="${testpath}/${test}.jmx"这行,替换为\<testplans dir="${basedir}/jmx" includes="*.jmx"/\>, 这里的脚本根目录需要根据自己的项目结构设置,resultlog就是测试产生的数据了-->
<!--修改测试数据结果保存的路径resultlog-->
<jmeter
jmeterhome="${jmeter.home}"
resultlog="${testpath}/result/test_data/${test}.jtl">
<testplans dir="${basedir}/jmx" includes="*.jmx"/>
<!--
<jvmarg value="-Xincgc"/>
<jvmarg value="-Xmx128m"/>
<jvmarg value="-Dproperty=value"/>
<jmeterarg value="-qextra.properties"/>
-->
<!-- Force suitable defaults -->
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="jmeter.save.saveservice.bytes" value="true"/>
<property name="file_format.testlog" value="${format}"/>
<property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>
</jmeter>
</target>
<property name="lib.dir" value="${jmeter.home}/lib"/>
<!-- Use xalan copy from JMeter lib directory to ensure consistent processing with Java 1.4+ -->
<path id="xslt.classpath">
<fileset dir="${lib.dir}" includes="xalan*.jar"/>
<fileset dir="${lib.dir}" includes="serializer*.jar"/>
</path>
<!--生成测试报告的任务-->
<!--不清楚copy-images任务是做什么的,因此这里先将该任务删除(copy-images)-->
<target name="report" depends="xslt-report">
<echo>Report generated at ${report.datestamp}</echo>
</target>
<target name="xslt-report" depends="_message_xalan">
<!--应为希望生成的测试报告带有时间戳,所以这里改变也一下时间的格式-->
<tstamp><format property="report.datestamp" pattern="yyyyMMddHHmmss"/></tstamp>
<!--修改in的值为自己生成测试数据的文件值-->
<!--修改out为放置测试报告的目录,并为生成报告的文件名添加上时间戳-->
<!--修改style路径-->
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/result/test_data/${test}.jtl"
out="${testpath}/result/report/${test}${report.datestamp}.html"
style="${jmeter.home}/extras/jmeter-results-detail-report${style_version}.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>
<!-- Copy report images if needed -->
<!--不清楚该任务,这里先将其注释掉了
<target name="copy-images" depends="verify-images" unless="samepath">
<copy file="${basedir}/resource/1.png" tofile="${testpath}/resource/1.png"/>
<copy file="${basedir}/resource/2.png" tofile="${testpath}/resource/2.png"/>
</target>
<target name="verify-images">
<condition property="samepath">
<equals arg1="${testpath}" arg2="${basedir}" />
</condition>
</target>
-->
<!-- Check that the xalan libraries are present -->
<condition property="xalan.present">
<and>
<!-- No need to check all jars; just check a few -->
<available classpathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
<available classpathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
</and>
</condition>
<target name="_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>
<target name="sendmail" description="sendtestreport">
<mail mailhost="smtp.126.com" user="pro_tes@126.com" password="******" messageMimeType="text/html" subject="ComingSoon" mailport="25" >
<from address="pro_tes@126.com" />
<to address="eric403225043@126.com" />
<message>This is autoPerfTest results we very happy to get this information. We are very glade to see you.</message>
</mail>
</target>
</project>