Using jtreg with Ant

Description

You can invoke jtreg from Ant, as well as from the command line. The class name is com.sun.javatest.regtest.Main$Ant. You will need to add the following to your build file to register the class with Ant.

        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant" 
            classpath="${jtreg.home}/lib/jtreg.jar" />
        

You can use any options that you would use on the command line by using a nested <arg> element. Alternatively, many options can also be specified directly.

This task forms an implicit FileSet and supports the nested <include>, <exclude> and <patternset> elements.

Parameters

ParametersDescriptionRequired
dir The base directory for the implicit FileSet. This may be the test-suite directory (as identified by the presence of TEST.ROOT), or any subdirectory within the test suite. It is also used as a base directory for any test files and directories that many be specified with nested <arg> elements. Yes, if nested fileset elements are used.
jdk The path for the JDK to use for the tests. No
otherVM Run each test in its own separate VM. Not both.
sameVM Run all tests in the same VM, where possible.
status Specify the prior status of tests to be selected to run. No
vmOptions A space-separated list of VM options to be used for the VM to run the tests. No
javacOptions A space-separated list of compiler options to be used to compile the tests. No
verbose Controls the amout of tracing output generated for each test. One of "all", "fail", "error", "pass", "summary", "default", "time"
workDir Specify where to put test result files. No
reportDir Specify where to put final test report. No
failOnError Stop the buildprocess if the command exits with a returncode other than 0. Default is "false" if any of "resultProperty", "failureProperty" or "errorProperty" are specified, and "true" if none of them are specified. No
resultProperty The name of a property in which the return code of the command should be stored. Only of interest if failonerror=false. No
failureProperty The name of a property to set in the event of a failure (errors are considered failures as well). No
errorProperty The name of a property to set in the event of an error. No

Nested elements

jtreg does not specify any new types of nested elements. However, you can use <arg> elements to provide any options that cannot be given as parameters, and you can use <include>, <exclude> and <patternset> elements in conjunction with the dir parameter to specify the tests to be run.

Note: If you specify a directory in the implicit fileset, jtreg will run all the tests in that directory, and in all its subdirectories. Therefore, as a general rule, you should not use the '**' pattern to specify a set of directories. You can use the '**' pattern to specify a set of files, such as '**/*.java'.

Examples

<jtreg dir="test/tools/javac"/>

Run all the tests in the test/tools/javac directory, using the same JDK being used to run Ant, the default work and report directories, and running each test in a separate VM.

<jtreg dir="test/tools/javac" workDir="myWorkDir"/>

As before, but specifying a work directory for the results.

<jtreg dir="test/tools/javac" workDir="myWorkDir">
    <include name="api/*.java" />
</jtreg>

Run just the api/*.java tests.

<jtreg>
    <arg line="-w myWorkDir -jdk /java/jdk/1.5.0 test/tools/javac">
</jtreg>

Run the test/tools/javac tests using /java/jdk/1.5.0 writing the results to myWorkDir.