Run a JUnit 4 test suite.
Task package: | org.junit.junit4 |
Java package: | org.schmant.task.junit4 |
Category: | Test tasks |
Since: | 0.5 |
EntityFS-aware? | No* |
Description:
Run a JUnit 4 test suite in a separate process.
Results from test runs are documented using JUnit4Reporter:s (the reporters property). See below for examples of how different reporters can be used.
The following strategy is used for searching for the java
command to use:
- Use a Java executable suggested by an ExtJavaTaskDecorator, if any
- Use the
javaExecutable
property, if set - Use the file
bin/java[.exe]
relative to thejavaHome
property, if set - Use the file
bin/java[.exe]
relative to theJAVA_HOME
environment variable, if set - Search for
java[.exe]
in the paths listed in thePATH
environment variable
Required properties
Properties
arguments | top |
Arguments to the program. The arguments will be given to the program in the order that they are added.
- Setter method:
addArgument(String arg)
Add one program argument.parameters:arg
– The program argument, for instance-f out.txt
.- Setter method:
addArguments(Object o)
Add one program argument or an array or a collection of program arguments.parameters:o
– One program argument or an array or collection of program arguments (strings).- Setter method:
clearArguments()
Clear the list of program arguments.
assertions | top |
Should Java assertions be enabled? More fine-grained assertion settings can be set by setting JVM options.
- Setter method:
setAssertions(boolean b)
parameters:b
– Should assertions be enabled?- Default value:
false
(assertions are not enabled).- See also:
- jvmOptions
classpathDecorators | top |
A collection of
PathDecorator:s that are used
to add entries to the classpath. The decorators are run in the order that they
are added to this property. Classpath decorator entries are added to the classpath after all entries added
manually to the classpathEntries
property.
- Setter method:
addClasspathDecorator(PathDecorator pd)
Add one classpath decorator to the end of the list.parameters:pd
– A classpath decorator.- Setter method:
addClasspathDecorators(Object o)
Add one or several classpath decorators.parameters:- Setter method:
clearClasspathDecorators()
Clear the list of classpath decorators.- See also:
- classpathEntries
classpathEntries | top |
Manually set classpath entries. An entry must be a Jar file or a class file directory.
- Setter method:
addClasspathEntries(Object o)
Add one or several classpath entries.parameters:o
– One or an array or collection of entries to add to the class path.
Interpreted byInterpretAsFileStrategy
.- Setter method:
addClasspathEntry(Object o)
Add one entry to the end of the class path.parameters:- Setter method:
clearClasspathEntries()
Clear the list of classpath entries.- See also:
- classpathDecorators
decorators | top |
A list of ExtJavaTaskDecorator:s. Decorators are used to configure the program to run.
- Setter method:
addDecorator(ExtJavaTaskDecorator d)
Add a decorator to the end of the list.parameters:d
– A Java task decorator- Setter method:
addDecorators(Object o)
Add one or several Java task decorators.parameters:o
– One Java task decorator or an array or collection of Java task decorators (ExtJavaTaskDecorator objects).- Setter method:
clearDecorators()
Clear the list of decorators.
environmentVariables | top |
Environment variables for the program. By default, the variables set are added
to the environment of the Schmant script. See the
inheritEnvironmentVariables
property.
- Setter method:
addEnvironmentVariable(String name, String value)
parameters:name
– The environment variable name, for instancePATH
.value
– The value of the variable.- Setter method:
addEnvironmentVariables(Object o)
Add one or several environment variables.parameters:o
– A string or an array or collection of strings. Each string must have the formatNAME=VALUE
.- Setter method:
clearEnvironmentVariables()
Clear the collection of environment variables.- See also:
- inheritEnvironmentVariables
failOnErrors | top |
If the program exits with an error (an exit code != 0), should the task fail? See also ErrorIgnoringTF.
- Setter method:
setFailOnErrors(boolean b)
parameters:b
– Should the task fail on errors?- Default value:
-
true
(fails on errors)
inheritEnvironmentVariables | top |
Should the environment variables of the Schmant script be inherited?
- Setter method:
setInheritEnvironmentVariables(boolean b)
parameters:b
– Should environment variables be inherited?- Default value:
true
(environment variables are inherited)- See also:
- environmentVariables
javaExecutable | top |
The path to the java[.exe]
command.
Decorators may also set the Java executable to use. In
that case, that setting take precedence.
- Setter method:
setJavaExecutable(Object o)
parameters:- Default value:
- The Java executable to use is, in this order of precedence:
- A Java executable set by any of the
decorators
. - This property.
- A Java executable found in the catalog referenced by the
javaHome
property, if set. - A Java executable found in the catalog referenced by the
JAVA_HOME
environment variable, if set. - A Java executable found in the directories referenced by the
PATH
environment variable.
- A Java executable set by any of the
- See also:
- javaHome
javaHome | top |
The location of the Java Runtime Environment or Java Development Kit to use
- Setter method:
setJavaHome(Object o)
parameters:- See also:
- javaExecutable
javaVMType | top |
The Java virtual machine type to use (client or server).
- Setter method:
setJavaVMType(JavaVMType t)
parameters:t
– The virtual machine type:JavaVMType.CLIENT
JavaVMType.SERVER
- Default value:
- The JVM:s default virtual machine type, probably client.
jvmOptions | top |
Options for the java
command. Options are
arguments to java
given before the class to run, see the JDK
documentation on java
.
- Setter method:
addJvmOption(String s)
parameters:s
– Add an option- Setter method:
addJvmOptions(Object o)
parameters:o
– One JVM option or an array or collection of JVM options (strings).- Setter method:
clearJvmOptions()
Clear the list of JVM options.
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
reporters | top |
A list of JUnit4Reporter:s for reporting the output from the test run.
- Setter method:
addReporter(JUnit4Reporter r)
Add one reporter.parameters:r
– A reporter.- Setter method:
addReporters(Object o)
Add one or several reporters.parameters:- Setter method:
clearReporters()
Clear the list of reporters.- Default value:
- A JUnit4SimpleReporter.
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
stderrStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stderr
.
- Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:s
– Thestderr
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.SEVERE
- See also:
- stdoutStrategy
stdoutStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stdout
.
- Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:s
– Thestdout
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.INFO
- See also:
- stderrStrategy
testClasses (required) | top |
A collection of the fully qualified names of test and/or test suite classes to run.
- Setter method:
addTestClass(String s)
Add one test class.parameters:s
– The fully qualified name of a test class.- Setter method:
addTestClasses(Object o)
Add one or several test classes.parameters:o
– One test class or an array or collection of test classes (fully qualified class names).- Setter method:
clearTestClasses()
Clear the collection of test classes.
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
workingDirectory | top |
The working directory for the program. (The directory that the program is started in.)
- Setter method:
setWorkingDirectory(Object o)
parameters:- Default value:
- The Schmant process' working directory. The Schmant launcher scripts sets this to the directory where the current script file is.
Examples
Example 1
Run the JUnit 4 test suite defined in the class
org.example.MyTestSuite1
. The Jar program.jar
contains
the code to test, and the Jar test.jar
contains the JUnit 4 test
classes. Both Jar files are in the lib
Directory.
JavaScript
Example 2
Run the test suites org.example.MyTestSuite1
and org.example.MyTestSuite2
and use a
JUnit4TestSuiteReporter to generate a test
report.
Groovy
JavaScript
JRuby
Jython
* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.