Class Funtest

  • All Implemented Interfaces:

    public class Funtest
    extends Task
    Task to provide functional testing under Ant, with a fairly complex workflow of:
    • Conditional execution
    • Application to start
    • A probe to "waitfor" before running tests
    • A tests sequence
    • A reporting sequence that runs after the tests have finished
    • A "teardown" clause that runs after the rest.
    • Automated termination of the program it executes, if a timeout is not met
    • Checking of a failure property and automatic raising of a fault (with the text in failureText) if test shutdown and reporting succeeded
    The task is designed to be framework neutral; it will work with JUnit, TestNG and other test frameworks That can be executed from Ant. It bears a resemblance to the FunctionalTest task from SmartFrog, as the attribute names were chosen to make migration easier. However, this task benefits from the ability to tweak Ant's internals, and so simplify the workflow, and from the experience of using the SmartFrog task. No code has been shared.
    Ant 1.8
    • Field Detail


        public static final java.lang.String WARN_OVERRIDING
        "Overriding previous definition of "
        See Also:
        Constant Field Values

        public static final java.lang.String APPLICATION_FORCIBLY_SHUT_DOWN
        "Application forcibly shut down"
        See Also:
        Constant Field Values

        public static final java.lang.String SHUTDOWN_INTERRUPTED
        "Shutdown interrupted"
        See Also:
        Constant Field Values

        public static final java.lang.String SKIPPING_TESTS
        "Condition failed -skipping tests"
        See Also:
        Constant Field Values

        public static final java.lang.String APPLICATION_EXCEPTION
        Application exception : "Application Exception"
        See Also:
        Constant Field Values

        public static final java.lang.String TEARDOWN_EXCEPTION
        Teardown exception : "Teardown Exception"
        See Also:
        Constant Field Values
    • Constructor Detail

      • Funtest

        public Funtest()
    • Method Detail

      • createCondition

        public ConditionBase createCondition()
        Add a condition element.
        Ant 1.6.2
      • addApplication

        public void addApplication​(Sequential sequence)
        Add an application.
        sequence - the application to add.
      • addSetup

        public void addSetup​(Sequential sequence)
        Add a setup sequence.
        sequence - the setup sequence to add.
      • addBlock

        public void addBlock​(BlockFor sequence)
        Add a block.
        sequence - the block for to add.
      • addTests

        public void addTests​(Sequential sequence)
        add tests.
        sequence - a sequence to add.
      • addReporting

        public void addReporting​(Sequential sequence)
        set reporting sequence of tasks.
        sequence - a reporting sequence to use.
      • addTeardown

        public void addTeardown​(Sequential sequence)
        set teardown sequence of tasks.
        sequence - a teardown sequence to use.
      • setFailOnTeardownErrors

        public void setFailOnTeardownErrors​(boolean failOnTeardownErrors)
        Set the failOnTeardownErrors attribute.
        failOnTeardownErrors - the value to use.
      • setFailureMessage

        public void setFailureMessage​(java.lang.String failureMessage)
        Set the failureMessage attribute.
        failureMessage - the value to use.
      • setFailureProperty

        public void setFailureProperty​(java.lang.String failureProperty)
        Set the failureProperty attribute.
        failureProperty - the value to use.
      • setShutdownTime

        public void setShutdownTime​(long shutdownTime)
        Set the shutdownTime attribute.
        shutdownTime - the value to use.
      • setTimeout

        public void setTimeout​(long timeout)
        Set the timeout attribute.
        timeout - the value to use.
      • setTimeoutUnit

        public void setTimeoutUnit​(WaitFor.Unit unit)
        Set the timeoutunit attribute.
        unit - the value to use.
      • setShutdownUnit

        public void setShutdownUnit​(WaitFor.Unit unit)
        Set the shutdownunit attribute.
        unit - the value to use.
      • getApplicationException

        public BuildException getApplicationException()
        Get the application exception.
        the application exception.
      • getTeardownException

        public BuildException getTeardownException()
        Get the teardown exception.
        the teardown exception.
      • getTestException

        public BuildException getTestException()
        Get the test exception.
        the test exception.
      • getTaskException

        public BuildException getTaskException()
        Get the task exception.
        the task exception.
      • execute

        public void execute()
                     throws BuildException
        Run the functional test sequence.

        This is a fairly complex workflow -what is going on is that we try to clean up no matter how the run ended, and to retain the innermost exception that got thrown during cleanup. That is, if teardown fails after the tests themselves failed, it is the test failing that is more important.

        execute in class Task
        BuildException - if something was caught during the run or teardown.
      • processExceptions

        protected void processExceptions()
        Now faults are analysed.

        The priority is

        1. testexceptions, except those indicating a build timeout when the application itself failed. (Because often it is the application fault that is more interesting than the probe failure, which is usually triggered by the application not starting.)
        2. Application exceptions (above test timeout exceptions)
        3. Teardown exceptions -except when they are being ignored
        4. Test failures as indicated by the failure property
      • ignoringThrowable

        protected void ignoringThrowable​(java.lang.String type,
                                         java.lang.Throwable thrown)
        log that we are ignoring something rather than rethrowing it.
        type - name of exception
        thrown - what was thrown