Package org.apache.ant.antunit
Class AntUnitScriptRunner
java.lang.Object
org.apache.ant.antunit.AntUnitScriptRunner
Run antunit tests suites. This AntUnitScriptRunner is responsible for the
management of the ant project and the correct invocation the target (taking
into account properly the [case]setUp and [case]tearDown targets).
The user can however provide the order of the test targets and or can filter
the list of test targets to execute.
The user must also provide its ProjectFactory and an AntUnitExecutionNotifier.
- Since:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Does that script have a setUp target (defined when scanning the script)private final boolean
Does that script has a suiteSetUp target.private final boolean
Does that script has a suite tearDown target that should be executed.private final boolean
Does that script have a tearDown target (defined when scanning the script)private boolean
Indicates if the startSuite method has been invoked.private final ProjectFactory
Object used to create projects in order to support test isolation.private org.apache.tools.ant.Project
The project currently used.private boolean
Indicates if a target has already be executed using this project.private static final String
name of the magic setUp target.private static final String
name of the magic suiteSetUp target.private static final String
name of the magic suiteTearDown target.private static final String
name of the magic tearDown target.private static final String
prefix that identifies test targets.private final List
List of target names -
Constructor Summary
ConstructorsConstructorDescriptionAntUnitScriptRunner
(ProjectFactory prjFactory) Create a new AntScriptRunner on the given environment. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
endSuite
(Throwable caught, AntUnitExecutionNotifier notifier) Executes the suiteTearDown target if presents and report any execution error.private void
fireFailOrError
(String targetName, org.apache.tools.ant.BuildException e, AntUnitExecutionNotifier notifier) Try to see whether the BuildException e is an AssertionFailedException or is caused by an AssertionFailedException.private org.apache.tools.ant.Project
Get a project that has not yet been used in order to execute a target on it.final org.apache.tools.ant.Project
Get the project currently in use.getName()
Provides the name of the active script.void
runSuite
(List suiteTargets, AntUnitExecutionNotifier notifier) Executes the suite.private void
runTarget
(String name, AntUnitExecutionNotifier notifier) Run the specific test target, possibly between the setUp and tearDown targets if it exists.private boolean
startSuite
(AntUnitExecutionNotifier notifier) Executes the suiteSetUp target if presents and report any execution error.
-
Field Details
-
SETUP
name of the magic setUp target.- See Also:
-
TEST
prefix that identifies test targets.- See Also:
-
TEARDOWN
name of the magic tearDown target.- See Also:
-
SUITESETUP
name of the magic suiteSetUp target.- See Also:
-
SUITETEARDOWN
name of the magic suiteTearDown target.- See Also:
-
prjFactory
Object used to create projects in order to support test isolation. -
isSuiteStarted
private boolean isSuiteStartedIndicates if the startSuite method has been invoked. Use to fail fast if the the caller forget to call the startSuite method -
hasSetUp
private final boolean hasSetUpDoes that script have a setUp target (defined when scanning the script) -
hasTearDown
private final boolean hasTearDownDoes that script have a tearDown target (defined when scanning the script) -
hasSuiteSetUp
private final boolean hasSuiteSetUpDoes that script has a suiteSetUp target. -
hasSuiteTearDown
private final boolean hasSuiteTearDownDoes that script has a suite tearDown target that should be executed. -
testTargets
List of target names -
project
private org.apache.tools.ant.Project projectThe project currently used. -
projectIsDirty
private boolean projectIsDirtyIndicates if a target has already be executed using this project. Value is undefined when project is null.
-
-
Constructor Details
-
AntUnitScriptRunner
Create a new AntScriptRunner on the given environment.- Parameters:
prjFactory
- A factory for the ant project that will contains the antunit test to execute. The factory might be invoked multiple time in order to provide test isolation.- Throws:
org.apache.tools.ant.BuildException
- The project can not be parsed
-
-
Method Details
-
getCurrentProject
public final org.apache.tools.ant.Project getCurrentProject() throws org.apache.tools.ant.BuildExceptionGet the project currently in use. The caller is not allowed to invoke a target or do anything that would break the isolation of the test targets.- Returns:
- the current project
- Throws:
org.apache.tools.ant.BuildException
- The project can not be parsed
-
getCleanProject
private org.apache.tools.ant.Project getCleanProject()Get a project that has not yet been used in order to execute a target on it. -
getTestTartgets
- Returns:
- List<String> List of test targets of the script file
-
getName
Provides the name of the active script.- Returns:
- name of the project
-
startSuite
Executes the suiteSetUp target if presents and report any execution error.A failure is reported to the notifier and by returning false. Note that if the method return false, you are not allowed to run targets.
- Returns:
- false in case of execution failure. true in case of success.
-
runTarget
Run the specific test target, possibly between the setUp and tearDown targets if it exists. Exception or failures are reported to the notifier.- Parameters:
name
- name of the test target to execute.notifier
- will receive execution notifications.
-
endSuite
Executes the suiteTearDown target if presents and report any execution error.- Parameters:
caught
- Any internal exception triggered (and caught) by the caller indicating that the execution could not be invoked as expected.notifier
- will receive execution notifications.
-
fireFailOrError
private void fireFailOrError(String targetName, org.apache.tools.ant.BuildException e, AntUnitExecutionNotifier notifier) Try to see whether the BuildException e is an AssertionFailedException or is caused by an AssertionFailedException. If so, fire a failure for given targetName. Otherwise fire an error. -
runSuite
Executes the suite.- Parameters:
suiteTargets
- An ordered list of test targets. It must be a sublist of getTestTargetsnotifier
- is notified on test progress
-