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:
java.lang.Cloneable
public class AntUnit extends org.apache.tools.ant.TaskRun 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 Classes Modifier and Type Class Description private classAntUnit.BuildToAntUnitListenerAdapts AntUnitListener to BuildListener.static classAntUnit.Referencestatic classAntUnit.ReferenceSetDefines a collection of inheritedreferences, with an optional nestedMapperthat maps them to new reference IDs in the target project.
-
Field Summary
Fields Modifier and Type Field Description private org.apache.tools.ant.types.resources.UnionbuildFilesThe build files to process.static java.lang.StringERROR_NO_TESTSMessage if no tests have been specified.static java.lang.StringERROR_NON_FILESMessage if non-File resources have been specified.static java.lang.StringERROR_TESTS_FAILEDMessage to print if an error or failure occured.private java.lang.StringerrorPropertyName of a property to set in case of an error.private interrorshas an error occured?private booleanfailOnErrorstop testing if an error or failure occurs?private intfailureshas a failure occured?private java.util.ArrayListlistenerslisteners.private AntUnitExecutionNotifiernotifierprivate java.util.ArrayListpropertySetspropertysets.private java.util.ArrayListreferenceSetsHolds references to be inherited by the test projectprivate AntUnitScriptRunnerscriptRunnerThe object responsible for the execution of the unit test.
-
Constructor Summary
Constructors Constructor Description AntUnit()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(AntUnitListener al)Add a test listener.voidadd(org.apache.tools.ant.types.ResourceCollection rc)Add build files to run as tests.voidaddPropertySet(org.apache.tools.ant.types.PropertySet ps)Add a PropertySet.voidaddReference(AntUnit.Reference reference)Add an inherited reference.private voidattachListeners(java.io.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.ProjectcreateProjectForFile(java.io.File f)Creates a new project instance and configures it.AntUnit.ReferenceSetcreateReferenceSet()Add a set of inherited references.private voiddoFile(java.io.File f)Processes a single build file.private voiddoResourceCollection(org.apache.tools.ant.types.ResourceCollection rc)Processes a ResourceCollection.voidexecute()Execute the tests.private voidfireEndTest(java.lang.String targetName)invokes endTest on all registered test listeners.private voidfireError(java.lang.String targetName, java.lang.Throwable t)invokes addError on all registered test listeners.private voidfireFail(java.lang.String targetName, AssertionFailedException ae)invokes addFailure on all registered test listeners.private voidfireStartTest(java.lang.String targetName)invokes start on all registered test listeners.voidhandleErrorFlush(java.lang.String errorOutputToFlush)Redirect error flush to new project instance.voidhandleErrorOutput(java.lang.String errorOutputToHandle)Redirect error output to new project instance.voidhandleFlush(java.lang.String toFlush)Redirect flush to new project instance.inthandleInput(byte[] buffer, int offset, int length)Redirect input to new project instance.voidhandleOutput(java.lang.String outputToHandle)Redirect output to new project instance.voidsetErrorProperty(java.lang.String s)Set the name of a property to set if an error or failure occurs.voidsetFailOnError(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
-
-
-
-
Field Detail
-
ERROR_TESTS_FAILED
public static final java.lang.String ERROR_TESTS_FAILED
Message to print if an error or failure occured.- See Also:
- Constant Field Values
-
ERROR_NO_TESTS
public static final java.lang.String ERROR_NO_TESTS
Message if no tests have been specified.- See Also:
- Constant Field Values
-
ERROR_NON_FILES
public static final java.lang.String ERROR_NON_FILES
Message if non-File resources have been specified.- See Also:
- Constant Field Values
-
buildFiles
private org.apache.tools.ant.types.resources.Union buildFiles
The build files to process.
-
notifier
private AntUnitExecutionNotifier notifier
-
scriptRunner
private AntUnitScriptRunner 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
private java.util.ArrayList listeners
listeners.
-
propertySets
private java.util.ArrayList propertySets
propertysets.
-
referenceSets
private java.util.ArrayList referenceSets
Holds references to be inherited by the test project
-
failures
private int failures
has a failure occured?
-
errors
private int errors
has an error occured?
-
failOnError
private boolean failOnError
stop testing if an error or failure occurs?
-
errorProperty
private java.lang.String errorProperty
Name of a property to set in case of an error.
-
-
Method Detail
-
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
public void add(AntUnitListener al)
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
public AntUnit.ReferenceSet createReferenceSet()
Add a set of inherited references.- Returns:
- set of inherited references
-
addReference
public void addReference(AntUnit.Reference reference)
Add an inherited reference.- Parameters:
reference- inherited reference
-
setErrorProperty
public void setErrorProperty(java.lang.String s)
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:
executein classorg.apache.tools.ant.Task
-
doResourceCollection
private void doResourceCollection(org.apache.tools.ant.types.ResourceCollection rc)
Processes a ResourceCollection.
-
doFile
private void doFile(java.io.File f)
Processes a single build file.
-
handleOutput
public void handleOutput(java.lang.String outputToHandle)
Redirect output to new project instance.- Overrides:
handleOutputin classorg.apache.tools.ant.Task- Parameters:
outputToHandle- the output to handle.
-
handleInput
public int handleInput(byte[] buffer, int offset, int length) throws java.io.IOExceptionRedirect input to new project instance.- Overrides:
handleInputin classorg.apache.tools.ant.Task- Parameters:
buffer- the buffer containing the input.offset- the offset intobuffer.length- the length of the data.- Throws:
java.io.IOException
-
handleFlush
public void handleFlush(java.lang.String toFlush)
Redirect flush to new project instance.- Overrides:
handleFlushin classorg.apache.tools.ant.Task- Parameters:
toFlush- the output String to flush.
-
handleErrorOutput
public void handleErrorOutput(java.lang.String errorOutputToHandle)
Redirect error output to new project instance.- Overrides:
handleErrorOutputin classorg.apache.tools.ant.Task- Parameters:
errorOutputToHandle- the error output to handle.
-
handleErrorFlush
public void handleErrorFlush(java.lang.String errorOutputToFlush)
Redirect error flush to new project instance.- Overrides:
handleErrorFlushin classorg.apache.tools.ant.Task- Parameters:
errorOutputToFlush- the error output to flush.
-
createProjectForFile
private org.apache.tools.ant.Project createProjectForFile(java.io.File f)
Creates a new project instance and configures it.- Parameters:
f- the File for which to create a Project.
-
attachListeners
private void attachListeners(java.io.File buildFile, org.apache.tools.ant.Project p)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
private void fireStartTest(java.lang.String targetName)
invokes start on all registered test listeners.- Parameters:
targetName- the name of the target.
-
fireFail
private void fireFail(java.lang.String targetName, AssertionFailedException ae)invokes addFailure on all registered test listeners.- Parameters:
targetName- the name of the failed target.ae- the associated AssertionFailedException.
-
fireError
private void fireError(java.lang.String targetName, java.lang.Throwable t)invokes addError on all registered test listeners.- Parameters:
targetName- the name of the failed target.t- the associated Throwable.
-
fireEndTest
private void fireEndTest(java.lang.String targetName)
invokes endTest on all registered test listeners.- Parameters:
targetName- the name of the current target.
-
-