English version (13)-testng and ant tasks

Source: Internet
Author: User
Tags testng
Document directory
  • Example
Testng and ant task

Use the following method to define testng in the ant task:

View Source code printing?
<taskdef resource="testngtasks" classpath="testng.jar"/>

The following tasks run the testng test and always run in the branch JVM. It accepts the following attributes:

Attribute Description Required
Annotations The "JDK" or "javadoc" string defines the annotation used in the test. If javadoc is used, you also need to specify "sourcedir ". No. The default value is "JDK". If you are using a JDK 5 package, the opposite is "javadoc". If you are using a JDK 1.4 package
Classfilesetref The structure of the fileset referenced by the test class to be run.  
Classpath Path. Path is similar to the test to run.  
Classpathref Reference of the test to be run in a certain path  
Dataproviderthreadcount The number of threads provided to the data provider to run the test. The default value is ignore unless the parallel mode is enabled. 1
Delegatecommandsystemproperties Pass the command line attribute to the system attribute Not required. The default value is false.
Dumpcommand Print the commands run by testng. Not required. The default value is false.
Enableassert Enable assertions of JDK 1.4 Not required. The default value is true.
Failureproperty The attribute name set in the failed event, only inHaltonfailureWhen no settings are available Not Required
Haltonfailure In the test run, if a failure occurs, the build process is stopped. Not required. The default value is false.  
Haltonskipped If at least one skipped test occurs, the build process is stopped. Not required. The default value is false.
Groups Names of groups to be run, separated by commas  
Excludedgroups Names of groups to be excluded, separated by commas  
JVM JVM to be usedRuntime.exe C () to call Java
Listeners A list of full-course class names separated by commas (,). The classes are used as listeners of testng (for exampleOrg. testng. itestlistenerOrOrg. testng. ireporter) Not Required
Outputdir Test report output directory Not required. The default value isTest-Output.
Skippedproperty When a skipped event occurs, the attribute name is onlyHaltonskippedIt takes effect when no settings are set. Not Required
Sourcedir Use the javadoc annotation for a test structure similar to the path used by JDK 1.4 (to put it bluntly, it is a directory)  
Sourcedirref Give JDK 1.4 a reference to the structure source code package that has been referenced in a path (using the annotation like javadoc)  
Suiterunnerclass Complete testng initiator Class Name

Not required. The default value isOrg. testng. testng

Parallel Run the test in parallel mode-either methods or tests It is not required if it does not appear. In this case, the parallel mode is not used.
Threadcount Number of threads in parallel mode. Ignored if the parallel mode is not used 1
Testjar Ambition: A path containing jar files defined by tests and suite  
Timeout In milliseconds, all tests can run for a maximum  
Usedefalistlisteners Whether to use the default listener and report Builder The default value is true.
Workingdir Working directory for ant to run testng  
Xmlfilesetref Reference to the fileset structure in the suite definition to be run.  
Suitename If the XML file or source code of suite is not specified, you can specify the name of test suite here. Not required. The default value is "ant suite"
Testname If the XML file or source code of the suite is not specified, you can specify the name of test here. Not required. The default value is "ant suite"

AttributeClasspath,ClasspathrefOr embedded<Classpath>The path of the class to run the test must be provided.

AttributeXmlfilesetref,ClassfilesetrefOr embedded<Xmlfileset>,<Classfileset> you must provide your own class tests..

NOTE: If JDK 1.4 is used, attributes must be used.Sourcedir,SourcedirrefOr embedded<Sourcedir>.

Note: Use<Classfileset>The test class will not be automatically added to your class path. You may need to repeat these classes to be correctly used in the task.

Embedded element classpath

<Testng>Tasks support embedded<Classpath>Element, which indicates a structure with the same path(Path-Like structure ).

Bootclasspath

The position of the Bootstrap program can be specified by using a similar path structure. IfForkIf it is not set, it is ignored.

Xmlfileset

Suite definition (Testng. xml) You can useFilesetStructure passed to task

Classfileset

Testng can also run classes directly by usingFilesetStructure.

Sourcedir

Path-like structure, used for classes that use javadoc-style annotations in JDK 1.4 Testing

Jvmarg

Embedded<Jvmarg>Other parameters that the element passes to the JVM, such:

View Source code printing
<testng>
   <jvmarg value="-Djava.compiler=NONE" />
   <!-- ... -->
</testng>
Sysproperty

Use<Sysproperty>Element to specify a special system property value for the class. These attributes can be called when the VM executes the test. Attributes of sub-elements andEnvironment VariableSame:

View Source code printing?
<testng>
   <sysproperty key="basedir" value="${basedir}"/>
   <!-- ... -->
</testng>

Will run the test and makebasedirProperty available to the test.

Reporter

Internal<Reporter>Elements can be used to inject custom report listeners, allowing you to set custom attributes to adjust the behavior of the report tool during runtime.
This element hasClassnameProperty, which is mandatory and specifies the class of the custom listener. To set the attributes of the report tool,<Reporter>Hidden Danger su can contain multiple embedded<Property>And providesNameValueValueProperties, see the following example:

View Source code printing?
<testng ...>
   ...
   <reporter classname="com.test.MyReporter">
      <property name="methodFilter" value="*insert*"/>
      <property name="enableFiltering" value="true"/>
   </reporter>
   ...
</testng>
View Source code printing?
public class MyReporter {
 
  public String getMethodFilter() {...}
  public void setMethodFilter(String methodFilter) {...}
  public boolean isEnableFiltering() {...}
  public void setEnableFiltering(boolean enableFiltering) {...}
  ...
}

You must consider that currently only a limited attribute type is supported:String, Int, Boolean, byte, Char, double, float, long, short.

Env

You can use<Env> element to pass environment variables for testng called in VM. About <Env>For more information about element attributes, seeExecTask description.

How can I view the source code in the example 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 view source code printing?
<testng classpathref="run.cp"
        outputDir="${testng.report.dir}"
        haltOnFailure="true"M verbose="2">
    <classfileset dir="${test.build.dir}" includes="**/*.class" />

</testng>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.