Class AntUnitScriptRunner


  • public class AntUnitScriptRunner
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private boolean hasSetUp
      Does that script have a setUp target (defined when scanning the script)
      private boolean hasSuiteSetUp
      Does that script has a suiteSetUp target.
      private boolean hasSuiteTearDown
      Does that script has a suite tearDown target that should be executed.
      private boolean hasTearDown
      Does that script have a tearDown target (defined when scanning the script)
      private boolean isSuiteStarted
      Indicates if the startSuite method has been invoked.
      private ProjectFactory prjFactory
      Object used to create projects in order to support test isolation.
      private org.apache.tools.ant.Project project
      The project currently used.
      private boolean projectIsDirty
      Indicates if a target has already be executed using this project.
      private static java.lang.String SETUP
      name of the magic setUp target.
      private static java.lang.String SUITESETUP
      name of the magic suiteSetUp target.
      private static java.lang.String SUITETEARDOWN
      name of the magic suiteTearDown target.
      private static java.lang.String TEARDOWN
      name of the magic tearDown target.
      private static java.lang.String TEST
      prefix that identifies test targets.
      private java.util.List testTargets
      List of target names
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void endSuite​(java.lang.Throwable caught, AntUnitExecutionNotifier notifier)
      Executes the suiteTearDown target if presents and report any execution error.
      private void fireFailOrError​(java.lang.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 getCleanProject()
      Get a project that has not yet been used in order to execute a target on it.
      org.apache.tools.ant.Project getCurrentProject()
      Get the project currently in use.
      java.lang.String getName()
      Provides the name of the active script.
      java.util.List getTestTartgets()  
      void runSuite​(java.util.List suiteTargets, AntUnitExecutionNotifier notifier)
      Executes the suite.
      private void runTarget​(java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SETUP

        private static final java.lang.String SETUP
        name of the magic setUp target.
        See Also:
        Constant Field Values
      • TEST

        private static final java.lang.String TEST
        prefix that identifies test targets.
        See Also:
        Constant Field Values
      • TEARDOWN

        private static final java.lang.String TEARDOWN
        name of the magic tearDown target.
        See Also:
        Constant Field Values
      • SUITESETUP

        private static final java.lang.String SUITESETUP
        name of the magic suiteSetUp target.
        See Also:
        Constant Field Values
      • SUITETEARDOWN

        private static final java.lang.String SUITETEARDOWN
        name of the magic suiteTearDown target.
        See Also:
        Constant Field Values
      • 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 java.util.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 Detail

      • 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 Detail

      • 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 java.util.List getTestTartgets()
        Returns:
        List<String> List of test targets of the script file
      • getName

        public java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.util.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