Movatterモバイル変換


[0]ホーム

URL:


testng-ant

TestNG Ant Task

You define the TestNG ant task as follows:

<taskdefresource="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 aResourceCollection containing the test classes to be run. Only File basedResourceCollections 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 toskip
dataProviderThreadCountThe number of threads to use for data providers for this run. Ignored unless the parallel mode is also specified.1
delegateCommandSystemPropertiesPass the command line properties as system properties.No. Defaults tofalse
dumpCommandPrint the TestNG launcher command.No. Defaults tofalse
failurePropertyThe name of a property to set in the event of a failure. It is used only if thehaltonfailure is not set.No.
haltonfailureStop the build process if a failure has occurred during the test run.No. Defaults tofalse
haltonskippedStop the build process if there is at least on skipped test.No. Defaults tofalse
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 byRuntime.exec()java
listeners No.
methodsA comma separated list of fully qualified class name and method. For e.g.,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 totestng.
outputdirDirectory for reports output.No. Defaults totest-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 toorg.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 specified.1
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 aResourceCollection containing the suite definitions to be run. Only File basedResourceCollections are supported (i.e.,FileSet). 
xmlPathInJarThe path of the XML file inside the jar file, only applicable if testJar was specifiedtestng.xml

[!TIP]One of attributesclasspath,classpathref or nested<classpath> must be used for providing the tests classpath.

[!TIP]One of the attributesxmlfilesetref,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:

[!NOTE]junit andmixed 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><jvmargvalue="-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><syspropertykey="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 thePropertySet page in theAnt manual for full details. Here’s a simple example:

<projectname="Hello World Project"><propertyname="myprop1"value="value 1"/><propertyname="myprop2"value="value 2"/><propertysetid="propset1"><propertyrefname="myprop1"/><propertyrefname="myprop2"/></propertyset><testngoutputdir="${testng.report.dir}"classpathref="run.cp"><xmlfilesetdir="${test15.dir}"includes="testng-single3.xml"/><propertysetrefid="propset1"/></testng></project>

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><!--... --><reporterclassname="com.test.MyReporter"><propertyname="methodFilter"value="*insert*"/><propertyname="enableFiltering"value="true"/></reporter><!--... --></testng>
publicclassMyReporter{publicStringgetMethodFilter(){/* code */}publicvoidsetMethodFilter(StringmethodFilter){/* code */}publicbooleanisEnableFiltering(){/* code */}publicvoidsetEnableFiltering(booleanenableFiltering){/* code */}// code}

You have to consider though that for the moment only a limited set of property types are supported:

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 theexec task.

Examples

Suite xml

<testngclasspathref="run.cp"outputDir="${testng.report.dir}"sourcedir="${test.src.dir}"haltOnfailure="true"><xmlfilesetdir="${test14.dir}"includes="testng.xml"/></testng>

Class FileSet

<testngclasspathref="run.cp"outputDir="${testng.report.dir}"haltOnFailure="true"verbose="2"><classfilesetdir="${test.build.dir}"includes="**/*.class"/></testng>
This site is open source.Improve this page.

[8]ページ先頭

©2009-2025 Movatter.jp