Package org.apache.ant.antunit
Class AntUnit
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.ant.antunit.AntUnit
- All Implemented Interfaces:
Cloneable
public class AntUnit
extends org.apache.tools.ant.Task
Run every target whose name starts with "test" in a set of build files.
Run the "setUp" target before each of them if present, same for "tearDown" after each "test*" target (targets named just "test" are ignored). If a target throws an AssertionFailedException, the test has failed; any other exception is considered an error (although BuildException will be scanned recursively for nested AssertionFailedExceptions).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Adapts AntUnitListener to BuildListener.static class
static class
Defines a collection of inheritedreferences
, with an optional nestedMapper
that maps them to new reference IDs in the target project. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.tools.ant.types.resources.Union
The build files to process.static final String
Message if no tests have been specified.static final String
Message if non-File resources have been specified.static final String
Message to print if an error or failure occured.private String
Name of a property to set in case of an error.private int
has an error occured?private boolean
stop testing if an error or failure occurs?private int
has a failure occured?private ArrayList
listeners.private AntUnitExecutionNotifier
private ArrayList
propertysets.private ArrayList
Holds references to be inherited by the test projectprivate AntUnitScriptRunner
The object responsible for the execution of the unit test.Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(AntUnitListener al) Add a test listener.void
add
(org.apache.tools.ant.types.ResourceCollection rc) Add build files to run as tests.void
addPropertySet
(org.apache.tools.ant.types.PropertySet ps) Add a PropertySet.void
addReference
(AntUnit.Reference reference) Add an inherited reference.private void
attachListeners
(File buildFile, org.apache.tools.ant.Project p) Wraps all registered test listeners in BuildListeners and attaches them to the new project instance.private org.apache.tools.ant.Project
Creates a new project instance and configures it.Add a set of inherited references.private void
Processes a single build file.private void
doResourceCollection
(org.apache.tools.ant.types.ResourceCollection rc) Processes a ResourceCollection.void
execute()
Execute the tests.private void
fireEndTest
(String targetName) invokes endTest on all registered test listeners.private void
invokes addError on all registered test listeners.private void
fireFail
(String targetName, AssertionFailedException ae) invokes addFailure on all registered test listeners.private void
fireStartTest
(String targetName) invokes start on all registered test listeners.void
handleErrorFlush
(String errorOutputToFlush) Redirect error flush to new project instance.void
handleErrorOutput
(String errorOutputToHandle) Redirect error output to new project instance.void
handleFlush
(String toFlush) Redirect flush to new project instance.int
handleInput
(byte[] buffer, int offset, int length) Redirect input to new project instance.void
handleOutput
(String outputToHandle) Redirect output to new project instance.void
Set the name of a property to set if an error or failure occurs.void
setFailOnError
(boolean failOnError) Set whether to stop testing if an error or failure occurs?Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Field Details
-
ERROR_TESTS_FAILED
Message to print if an error or failure occured.- See Also:
-
ERROR_NO_TESTS
Message if no tests have been specified.- See Also:
-
ERROR_NON_FILES
Message if non-File resources have been specified.- See Also:
-
buildFiles
private org.apache.tools.ant.types.resources.Union buildFilesThe build files to process. -
notifier
-
scriptRunner
The object responsible for the execution of the unit test. scriptRunner is invoked to executes the targets and keep the reference to the project. scriptRunner is defined only when the antunit script is running. -
listeners
listeners. -
propertySets
propertysets. -
referenceSets
Holds references to be inherited by the test project -
failures
private int failureshas a failure occured? -
errors
private int errorshas an error occured? -
failOnError
private boolean failOnErrorstop testing if an error or failure occurs? -
errorProperty
Name of a property to set in case of an error.
-
-
Constructor Details
-
AntUnit
public AntUnit()
-
-
Method Details
-
add
public void add(org.apache.tools.ant.types.ResourceCollection rc) Add build files to run as tests.- Parameters:
rc
- the ResourceCollection to add.
-
add
Add a test listener.- Parameters:
al
- the AntUnitListener to add.
-
addPropertySet
public void addPropertySet(org.apache.tools.ant.types.PropertySet ps) Add a PropertySet.- Parameters:
ps
- the PropertySet to add.
-
createReferenceSet
Add a set of inherited references.- Returns:
- set of inherited references
-
addReference
Add an inherited reference.- Parameters:
reference
- inherited reference
-
setErrorProperty
Set the name of a property to set if an error or failure occurs.- Parameters:
s
- the name of the error property.
-
setFailOnError
public void setFailOnError(boolean failOnError) Set whether to stop testing if an error or failure occurs?- Parameters:
failOnError
- defaulttrue
-
execute
public void execute()Execute the tests.- Overrides:
execute
in classorg.apache.tools.ant.Task
-
doResourceCollection
private void doResourceCollection(org.apache.tools.ant.types.ResourceCollection rc) Processes a ResourceCollection. -
doFile
Processes a single build file. -
handleOutput
Redirect output to new project instance.- Overrides:
handleOutput
in classorg.apache.tools.ant.Task
- Parameters:
outputToHandle
- the output to handle.
-
handleInput
Redirect input to new project instance.- Overrides:
handleInput
in classorg.apache.tools.ant.Task
- Parameters:
buffer
- the buffer containing the input.offset
- the offset intobuffer
.length
- the length of the data.- Throws:
IOException
-
handleFlush
Redirect flush to new project instance.- Overrides:
handleFlush
in classorg.apache.tools.ant.Task
- Parameters:
toFlush
- the output String to flush.
-
handleErrorOutput
Redirect error output to new project instance.- Overrides:
handleErrorOutput
in classorg.apache.tools.ant.Task
- Parameters:
errorOutputToHandle
- the error output to handle.
-
handleErrorFlush
Redirect error flush to new project instance.- Overrides:
handleErrorFlush
in classorg.apache.tools.ant.Task
- Parameters:
errorOutputToFlush
- the error output to flush.
-
createProjectForFile
Creates a new project instance and configures it.- Parameters:
f
- the File for which to create a Project.
-
attachListeners
Wraps all registered test listeners in BuildListeners and attaches them to the new project instance.- Parameters:
buildFile
- a build file.p
- the Project to attach to.
-
fireStartTest
invokes start on all registered test listeners.- Parameters:
targetName
- the name of the target.
-
fireFail
invokes addFailure on all registered test listeners.- Parameters:
targetName
- the name of the failed target.ae
- the associated AssertionFailedException.
-
fireError
invokes addError on all registered test listeners.- Parameters:
targetName
- the name of the failed target.t
- the associated Throwable.
-
fireEndTest
invokes endTest on all registered test listeners.- Parameters:
targetName
- the name of the current target.
-