Class AntUnitScriptRunner

java.lang.Object
org.apache.ant.antunit.AntUnitScriptRunner

public class AntUnitScriptRunner extends Object
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 Details

    • SETUP

      private static final String SETUP
      name of the magic setUp target.
      See Also:
    • TEST

      private static final String TEST
      prefix that identifies test targets.
      See Also:
    • TEARDOWN

      private static final String TEARDOWN
      name of the magic tearDown target.
      See Also:
    • SUITESETUP

      private static final String SUITESETUP
      name of the magic suiteSetUp target.
      See Also:
    • SUITETEARDOWN

      private static final String SUITETEARDOWN
      name of the magic suiteTearDown target.
      See Also:
    • prjFactory

      private final ProjectFactory prjFactory
      Object used to create projects in order to support test isolation.
    • isSuiteStarted

      private boolean isSuiteStarted
      Indicates 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 hasSetUp
      Does that script have a setUp target (defined when scanning the script)
    • hasTearDown

      private final boolean hasTearDown
      Does that script have a tearDown target (defined when scanning the script)
    • hasSuiteSetUp

      private final boolean hasSuiteSetUp
      Does that script has a suiteSetUp target.
    • hasSuiteTearDown

      private final boolean hasSuiteTearDown
      Does that script has a suite tearDown target that should be executed.
    • testTargets

      private final List testTargets
      List of target names
    • project

      private org.apache.tools.ant.Project project
      The project currently used.
    • projectIsDirty

      private boolean projectIsDirty
      Indicates if a target has already be executed using this project. Value is undefined when project is null.
  • Constructor Details

    • AntUnitScriptRunner

      public AntUnitScriptRunner(ProjectFactory prjFactory) throws org.apache.tools.ant.BuildException
      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.BuildException
      Get 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

      public List getTestTartgets()
      Returns:
      List<String> List of test targets of the script file
    • getName

      public String getName()
      Provides the name of the active script.
      Returns:
      name of the project
    • startSuite

      private boolean startSuite(AntUnitExecutionNotifier notifier)
      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

      private void runTarget(String name, AntUnitExecutionNotifier notifier)
      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

      private void endSuite(Throwable caught, AntUnitExecutionNotifier notifier)
      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

      public void runSuite(List suiteTargets, AntUnitExecutionNotifier notifier)
      Executes the suite.
      Parameters:
      suiteTargets - An ordered list of test targets. It must be a sublist of getTestTargets
      notifier - is notified on test progress