http://testng.org/doc/ant.html
TestNG Ant Task
You define the TestNG ant task as follows:
< taskdef
resource = "testngtasks"
classpath = "testng.jar" />
|
This task runs TestNG tests and is always run in a forked JVM. It accepts the following attributes:
Attribute
Description
Required
classfilesetref |
A reference to a
ResourceCollection containing the test classes to be run. Only File based
ResourceCollections are supported (ie.
FileSet). |
|
classpath |
A PATH-like structure for the tests to be run. |
|
classpathref |
A reference to a PATH-like structure for the tests to be run. |
|
configFailurePolicy |
Whether TestNG should continue to execute the remaining tests in the suite or
skip them if an @Before* method fails. |
No. Defaults to skip
|
dataProviderThreadCount |
The number of threads to use for data providers for this run. Ignored unless the parallel mode is also specified |
1 |
delegateCommandSystemProperties |
Pass the command line properties as system properties. |
No. Defaults to false |
dumpCommand |
Print the TestNG launcher command. |
No. Defaults to false |
failureProperty |
The name of a property to set in the event of a failure. It is used only if the
haltonfailure is not set. |
No. |
haltonfailure |
Stop the build process if a failure has occurred during the test run. |
No. Defaults to false |
|
haltonskipped |
Stop the build process if there is at least on skipped test. |
No. Default to false |
groups |
The list of groups to run, separated by spaces or commas. |
|
excludedgroups |
The list of groups to exclude, separated by spaces or commas |
|
jvm |
The JVM to use, which will be run by Runtime.exec()
|
java |
listeners |
A comma or space-separated list of fully qualified classes that are TestNG listeners (for example
org.testng.ITestListener or
org.testng.IReporter)
|
No. |
methods |
A comma separated list of fully qualified class name and method. For example
com.example.Foo.f1,com.example.Bar.f2. |
No. |
mode |
Either "testng", "junit" or "mixed". Whether TestNG should run only TestNG tests, JUnit tests or both. |
No. Defaults to "testng". |
outputdir |
Directory for reports output. |
No. Defaults to test-output. |
skippedProperty |
The name of a property to set in the event of a skipped test. It is used only if the
haltonskipped is not set. |
No. |
suiteRunnerClass |
A fully qualified name of a TestNG starter. |
No. Defaults to org.testng.TestNG
|
suiteThreadPoolSize |
The size of a thread pool to run suites. |
No. Defaults to 1.
|
parallel |
The parallel mode to use for running the tests - either methods or tests |
No - if not present, parallel mode will not be selected |
suitename |
Sets the default name of the test suite, if one is not specified in a suite xml file or in the source code |
No. Defaults to "Ant suite" |
testJar |
Path to a jar containing tests and a suite definition. |
|
testname |
Sets the default name of the test, if one is not specified in a suite xml file or in the source code |
No. defaults to "Ant test" |
testnames |
A comma separated list of test names, as defined in the <test> tag. Only these tests will be run. |
No. defaults to "Ant test" |
threadCount |
The number of threads to use for this run. Ignored unless the parallel mode is also specified |
1 |
timeOut |
The maximum time out in milliseconds that all the tests should run under. |
|
useDefaultListeners |
Whether the default listeners and reporters should be used. |
Defaults to true. |
workingDir |
The directory where the ant task should change to before running TestNG. |
|
xmlfilesetref |
A reference to a
ResourceCollection containing the suite definitions to be run. Only File based
ResourceCollections are supported (ie.
FileSet). |
|
xmlPathInJar |
The path of the XML file inside the jar file, only applicable if testJar was specified |
testng.xml |
One of attributes
classpath,
classpathref or nested
<classpath> must be used for providing the tests classpath.
One of the attributes xmlfilesetref, classfilesetref or nested
<xmlfileset>, respectively <classfileset> must be used for providing the tests.
TestNG modes
The TestNG mode gets applied when tests are passed to TestNG using classfilesetref,
methods or nested <classfileset> and tells TestNG what kind of tests it should look for and run:
-
"testng": find and run TestNG tests.
-
"junit": find and run JUnit tests.
-
"mixed": run both TestNG and JUnit tests.
Note: "junit" and "mixed" modes require the JUnit jar file on the classpath.
classpath
The <testng> task supports a nested <classpath> element that represents a
PATH-like structure.
bootclasspath
The location of bootstrap class files can be specified using this PATH-like structure - will be ignored if
fork is not set.
xmlfileset
The suite definitions (testng.xml) can be passed to the task with a
FileSet structure.
classfileset
TestNG can also run directly on classes, also supplied with a FileSet structure.
jvmarg
Additional parameters may be passed to the new VM via nested <jvmarg> elements. For example:
< jvmarg
value = "-Djava.compiler=NONE"
/>
|
sysproperty
Use nested <sysproperty> elements to specify system properties required by the class. These properties will be made available to the virtual machine during the execution of the test. The attributes for this element are the same as for
environment variables:
< sysproperty
key = "basedir"
value = "${basedir}" />
|
will run the test and make the basedir
property available to the test.
propertyset
You may also use a nested <propertyset> element to specify a set of system properties that are defined outside of the TestNG ant task. This allows for more flexible definitions of system properties, for instance selecting all properties with a specific
prefix or matching a regex. See the
PropertySet page in the Ant manual for full details. Here's a simple example:
< property
name = "myprop1"
value = "value 1" />
|
< property
name = "myprop2"
value = "value 2" />
|
< propertyset
id = "propset1" >
|
< propertyref
name = "myprop1" />
|
< propertyref
name = "myprop2" />
|
< testng
outputdir = "${testng.report.dir}"
classpathref = "run.cp" >
|
< xmlfileset
dir = "${test15.dir}"
includes = "testng-single3.xml" />
|
< propertyset
refid = "propset1" />
|
In this case, the system properties named "myprop1" and "myprop2" are passed along to the TestNG process.
reporter
An inner <reporter> element is an alternative way to inject a custom report listener allowing the user to set custom properties in order to fine-tune the behavior of the reporter at run-time.
The element has one classname attribute which is mandatory, indicating the class of the custom listener. In order to set the properties of the reporter, the
<reporter> element can contain several nested <property> elements which will provide the
name and value attributes as seen below:
< reporter
classname = "com.test.MyReporter" >
|
< property
name = "methodFilter"
value = "*insert*" />
|
< property
name = "enableFiltering"
value = "true" />
|
public
class MyReporter {
|
public
String getMethodFilter() {...}
|
public
void setMethodFilter(String methodFilter) {...}
|
public
boolean isEnableFiltering() {...}
|
public
void setEnableFiltering( boolean
enableFiltering) {...}
|
You have to consider though that for the moment only a limited set of property types are supported:
String, int, boolean, byte, char, double, float, long, short.
env
It is possible to specify environment variables to pass to the TestNG forked virtual machine via nested
<env> elements. For a description of the <env> element's attributes, see the description in the
exec task.
Examples
Suite xml
<testng classpathref="run.cp"
|
outputDir="${testng.report.dir}"
|
sourcedir="${test.src.dir}"
|
<xmlfileset dir="${test14.dir}" includes="testng.xml"/>
|
Class FileSet
< testng
classpathref = "run.cp"
|
outputDir = "${testng.report.dir}"
|
haltOnFailure = "true" M
verbose = "2" >
|
< classfileset
dir = "${test.build.dir}"
includes = "**/*.class"
/>
|
分享到:
相关推荐
ant+selenium+testng自动化测试方案
ant + Selenium2 + testNG 整合的相关例子,可供参考
搭建selenium+testng+reportng+ant框架
WebDriver+TestNG+ANT_实现多浏览器兼容性测试 ,.............................................
ant 命令行 让我们调用使用testng.xml文件。创建一个XML文件名称testng.xml C:\ > TestNG_WORKSPACE 执行测试用例(s) <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > </suite> 第...
1.下载testNG 离线安装包【eclipse-testng离线包】,并解压。 2.将解压后的文件..\eclipse-testng离线包\features\目录下的文件夹org.testng.eclipse_6.11.0.201703011520放到eclipse安装路径下的features目录下 3....
1、testng测试报告模板BeautifulReport 2、testng.xml文件
1. 将解压后的文件..\eclipse-testng离线包\features\org.testng.eclipse_6.9.9.201510270734 文件夹 放到 eclipse--》features目录下 2. 将解压后的文件..\eclipse-testng离线包\plugins\org.testng.eclipse_6.9...
jenkins + ant + testng + reportng自动集成测试操作手册,该手册是小兔自己编写的,写的不明白的地方,请大家多多指正
testNG 自动化测试工具 工具类 testng-6.3.jar
testng-6.8.8
testng-6.9-10 jar包
1. 将解压后的文件..\eclipse-testng离线包\features\org.testng.eclipse_6.9.9.201510270734 文件夹 放到 eclipse--》features目录下 2. 将解压后的文件..\eclipse-testng离线包\plugins\org.testng.eclipse_...
testNg介绍
[Packt Publishing] TestNG 初学者指南 (英文版) [Packt Publishing] TestNG Beginner's Guide (E-Book) ☆ 图书概要:☆ Write robust unit and functional tests with the power of TestNG Overview Step-by-...
2.将解压后的文件..\eclipse-testng离线包\features\目录下的文件夹org.testng.eclipse_6.8.6.20130607_0745放到eclipse-->features目录下 3.将解压后的文件..\eclipse-testng离线包\org.testng.eclipse_6.8.6....
1.下载testNG 离线安装包【eclipse-testng离线包】,并解压。 2.将解压后的文件..\eclipse-testng离线包\features\目录下的文件夹org.testng.eclipse_6.9.8.201510130443放到eclipse安装路径下的features目录下 3.将...
最新testng jar包,testng-6.9.6.jar
testng-xslt-1.1.2.zip
TestNG依赖包,包含了org.testng.CommandLineArgs类,导入后可解决因找不到依赖而出现的问题