TestNG Ant Task

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:

AttributeDescriptionRequired
classfilesetrefA reference to a ResourceCollection containing the test classes to be run. Only File based ResourceCollections are supported (ie. FileSet).
classpathA PATH-like structure for the tests to be run.
classpathrefA reference to a PATH-like structure for the tests to be run.
configFailurePolicyWhether TestNG should continue to execute the remaining tests in the suite or skip them if an @Before* method fails.No. Defaults to skip
dataProviderThreadCountThe number of threads to use for data providers for this run. Ignored unless the parallel mode is also specified1
delegateCommandSystemPropertiesPass the command line properties as system properties.No. Defaults to false
dumpCommandPrint the TestNG launcher command.No. Defaults to false
failurePropertyThe name of a property to set in the event of a failure. It is used only if the haltonfailure is not set.No.
haltonfailureStop the build process if a failure has occurred during the test run.No. Defaults to false
haltonskippedStop the build process if there is at least on skipped test.No. Default to false
groupsThe list of groups to run, separated by spaces or commas.
excludedgroupsThe list of groups to exclude, separated by spaces or commas
jvmThe JVM to use, which will be run by Runtime.exec() java
listenersA comma or space-separated list of fully qualified classes that are TestNG listeners (for example org.testng.ITestListener or org.testng.IReporter) No.
methodsA comma separated list of fully qualified class name and method. For example com.example.Foo.f1,com.example.Bar.f2.No.
modeEither "testng", "junit" or "mixed". Whether TestNG should run only TestNG tests, JUnit tests or both.No. Defaults to "testng".
outputdirDirectory for reports output.No. Defaults to test-output.
skippedPropertyThe name of a property to set in the event of a skipped test. It is used only if the haltonskipped is not set.No.
suiteRunnerClassA fully qualified name of a TestNG starter.

No. Defaults to org.testng.TestNG

suiteThreadPoolSizeThe size of a thread pool to run suites.

No. Defaults to 1.

parallelThe parallel mode to use for running the tests - either methods or testsNo - if not present, parallel mode will not be selected
suitenameSets the default name of the test suite, if one is not specified in a suite xml file or in the source codeNo. Defaults to "Ant suite"
testJarPath to a jar containing tests and a suite definition.
testnameSets the default name of the test, if one is not specified in a suite xml file or in the source codeNo. defaults to "Ant test"
testnamesA comma separated list of test names, as defined in the <test> tag. Only these tests will be run.No. defaults to "Ant test"
threadCountThe number of threads to use for this run. Ignored unless the parallel mode is also specified1
timeOutThe maximum time out in milliseconds that all the tests should run under.
useDefaultListenersWhether the default listeners and reporters should be used.Defaults to true.
workingDirThe directory where the ant task should change to before running TestNG.
xmlfilesetrefA reference to a ResourceCollection containing the suite definitions to be run. Only File based ResourceCollections are supported (ie. FileSet).
xmlPathInJarThe path of the XML file inside the jar file, only applicable if testJar was specifiedtestng.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.

Nested Elements

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:

<testng>
<jvmarg value="-Djava.compiler=NONE" />
<!-- ... -->
</testng>
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:

<testng>
<sysproperty key="basedir" value="${basedir}"/>
<!-- ... -->
</testng>

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"/>
</propertyset>
<testng outputdir="${testng.report.dir}" classpathref="run.cp">
<xmlfileset dir="${test15.dir}" includes="testng-single3.xml"/>
<propertyset refid="propset1"/>
</testng>

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:

<testng ...>
...
<reporter classname="com.test.MyReporter">
<property name="methodFilter" value="*insert*"/>
<property name="enableFiltering" value="true"/>
</reporter>
...
</testng>
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}"
haltOnfailure="true">
<xmlfileset dir="${test14.dir}" includes="testng.xml"/>
</testng>
Class FileSet
<testng classpathref="run.cp"
outputDir="${testng.report.dir}"
haltOnFailure="true"M verbose="2">
<classfileset dir="${test.build.dir}" includes="**/*.class" />
</testng>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值