Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional.testing

public Class Funtest

extends Task
Class Inheritance
Imports
org.apache.tools.ant.BuildException, .Project, .Task, .TaskAdapter, org.apache.tools.ant.taskdefs.Parallel, .Sequential, .WaitFor, org.apache.tools.ant.taskdefs.condition.Condition, .ConditionBase, org.apache.tools.ant.util.WorkerAnt

Task to provide functional testing under Ant, with a fairly complex workflow of: 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.
Since
Ant 1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private Sequential
application

The application to run

public static final String
APPLICATION_EXCEPTION

Application exception : Application Exception

public static final String
APPLICATION_FORCIBLY_SHUT_DOWN

Application forcibly shut down

private BuildException
applicationException

Did the application throw an exception

private BlockFor
block

A block that halts the tests until met.

private Funtest.NestedCondition
condition

A condition that must be true before the tests are run.

private boolean
failOnTeardownErrors

Flag to set to true if you don't care about any shutdown errors.

private String
failureMessage

Message to send when tests failed

private String
failureProperty

Name of a property to look for

private Sequential
reporting

Reporting only runs if the tests were executed.

private Sequential
setup

Setup runs if the condition is met.

public static final String
SHUTDOWN_INTERRUPTED

Shutdown interrupted

private long
shutdownTime

time for the execution to time out.

private long
public static final String
SKIPPING_TESTS

Condition failed -skipping tests

private BuildException
taskException

Did the task throw an exception

private Sequential
teardown

Any teardown operations.

public static final String
TEARDOWN_EXCEPTION

Teardown exception : Teardown Exception

private BuildException
teardownException

What got thrown during teardown

private BuildException
testException

What was thrown in the test run (including reporting)

private Sequential
tests

Tests to run

private Parallel
timedTests

Used internally to set the workflow up

private long
timeout

time for the tests to time out

private long
public static final String
WARN_OVERRIDING

Overriding previous definition of

Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addApplication(Sequential
the application to add.
sequence
)

Add an application.

public void
addBlock(BlockFor
the block for to add.
sequence
)

Add a block.

public void
addReporting(Sequential
a reporting sequence to use.
sequence
)

set reporting sequence of tasks.

public void
addSetup(Sequential
the setup sequence to add.
sequence
)

Add a setup sequence.

public void
addTeardown(Sequential
a teardown sequence to use.
sequence
)

set teardown sequence of tasks.

public void
addTests(Sequential
a sequence to add.
sequence
)

add tests.

private void
bind(Task
task to bind
task
)

Bind and initialise a task

public ConditionBase

Returns:

ConditionBase.
createCondition
()

Add a condition element.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Run the functional test sequence.
public BuildException

Returns:

the application exception.
getApplicationException
()

Get the application exception.

public BuildException

Returns:

the task exception.
getTaskException
()

Get the task exception.

public BuildException

Returns:

the teardown exception.
getTeardownException
()

Get the teardown exception.

public BuildException

Returns:

the test exception.
getTestException
()

Get the test exception.

protected void
ignoringThrowable(String
name of exception
type
,
Throwable
what was thrown
thrown
)

log that we are ignoring something rather than rethrowing it.

private void
logOverride(String
what is being defined
name
,
Object
what should be null if you don't want a warning
definition
)

Log if the definition is overriding something

private Parallel

Returns:

a bound and initialised parallel instance.
newParallel
(long
timeout
parallelTimeout
)

Create a newly bound parallel instance

private Parallel

Returns:

a bound and initialised parallel instance.
newParallel
(long
timeout
parallelTimeout
,
Task
task
child
)

Create a newly bound parallel instance with one child

protected void
processExceptions()

Now faults are analysed.

public void
setFailOnTeardownErrors(boolean
the value to use.
failOnTeardownErrors
)

Set the failOnTeardownErrors attribute.

public void
setFailureMessage(String
the value to use.
failureMessage
)

Set the failureMessage attribute.

public void
setFailureProperty(String
the value to use.
failureProperty
)

Set the failureProperty attribute.

public void
setShutdownTime(long
the value to use.
shutdownTime
)

Set the shutdownTime attribute.

public void
setShutdownUnit(WaitFor.Unit
the value to use.
unit
)

Set the shutdownunit attribute.

public void
setTimeout(long
the value to use.
timeout
)

Set the timeout attribute.

public void
setTimeoutUnit(WaitFor.Unit
the value to use.
unit
)

Set the timeoutunit attribute.

private void
validateTask(Task
task
task
,
String
role of the task
role
)

Add any task validation needed to ensure internal code quality

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

applicationback to summary
private Sequential application

The application to run

APPLICATION_EXCEPTIONback to summary
public static final String APPLICATION_EXCEPTION

Application exception : Application Exception

APPLICATION_FORCIBLY_SHUT_DOWNback to summary
public static final String APPLICATION_FORCIBLY_SHUT_DOWN

Application forcibly shut down

applicationExceptionback to summary
private BuildException applicationException

Did the application throw an exception

blockback to summary
private BlockFor block

A block that halts the tests until met.

conditionback to summary
private Funtest.NestedCondition condition

A condition that must be true before the tests are run. This makes it easier to define complex tests that only run if certain conditions are met, such as OS or network state.

failOnTeardownErrorsback to summary
private boolean failOnTeardownErrors

Flag to set to true if you don't care about any shutdown errors.

In that situation, errors raised during teardown are logged but not turned into BuildFault events. Similar to catching and ignoring finally {} clauses in Java/

failureMessageback to summary
private String failureMessage

Message to send when tests failed

failurePropertyback to summary
private String failureProperty

Name of a property to look for

reportingback to summary
private Sequential reporting

Reporting only runs if the tests were executed. If the block stopped them, reporting is skipped.

setupback to summary
private Sequential setup

Setup runs if the condition is met. Once setup is complete, teardown will be run when the task finishes

SHUTDOWN_INTERRUPTEDback to summary
public static final String SHUTDOWN_INTERRUPTED

Shutdown interrupted

shutdownTimeback to summary
private long shutdownTime

time for the execution to time out.

shutdownUnitMultiplierback to summary
private long shutdownUnitMultiplier
SKIPPING_TESTSback to summary
public static final String SKIPPING_TESTS

Condition failed -skipping tests

taskExceptionback to summary
private BuildException taskException

Did the task throw an exception

teardownback to summary
private Sequential teardown

Any teardown operations.

TEARDOWN_EXCEPTIONback to summary
public static final String TEARDOWN_EXCEPTION

Teardown exception : Teardown Exception

teardownExceptionback to summary
private BuildException teardownException

What got thrown during teardown

testExceptionback to summary
private BuildException testException

What was thrown in the test run (including reporting)

testsback to summary
private Sequential tests

Tests to run

timedTestsback to summary
private Parallel timedTests

Used internally to set the workflow up

timeoutback to summary
private long timeout

time for the tests to time out

timeoutUnitMultiplierback to summary
private long timeoutUnitMultiplier
WARN_OVERRIDINGback to summary
public static final String WARN_OVERRIDING

Overriding previous definition of

Constructor Detail

Funtestback to summary
public Funtest()

Method Detail

addApplicationback to summary
public void addApplication(Sequential sequence)

Add an application.

Parameters
sequence:Sequential

the application to add.

addBlockback to summary
public void addBlock(BlockFor sequence)

Add a block.

Parameters
sequence:BlockFor

the block for to add.

addReportingback to summary
public void addReporting(Sequential sequence)

set reporting sequence of tasks.

Parameters
sequence:Sequential

a reporting sequence to use.

addSetupback to summary
public void addSetup(Sequential sequence)

Add a setup sequence.

Parameters
sequence:Sequential

the setup sequence to add.

addTeardownback to summary
public void addTeardown(Sequential sequence)

set teardown sequence of tasks.

Parameters
sequence:Sequential

a teardown sequence to use.

addTestsback to summary
public void addTests(Sequential sequence)

add tests.

Parameters
sequence:Sequential

a sequence to add.

bindback to summary
private void bind(Task task)

Bind and initialise a task

Parameters
task:Task

task to bind

createConditionback to summary
public ConditionBase createCondition()

Add a condition element.

Returns:ConditionBase

ConditionBase.

Since
Ant 1.6.2
executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

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.

Annotations
@Override
Exceptions
BuildException:
if something was caught during the run or teardown.
getApplicationExceptionback to summary
public BuildException getApplicationException()

Get the application exception.

Returns:BuildException

the application exception.

getTaskExceptionback to summary
public BuildException getTaskException()

Get the task exception.

Returns:BuildException

the task exception.

getTeardownExceptionback to summary
public BuildException getTeardownException()

Get the teardown exception.

Returns:BuildException

the teardown exception.

getTestExceptionback to summary
public BuildException getTestException()

Get the test exception.

Returns:BuildException

the test exception.

ignoringThrowableback to summary
protected void ignoringThrowable(String type, Throwable thrown)

log that we are ignoring something rather than rethrowing it.

Parameters
type:String

name of exception

thrown:Throwable

what was thrown

logOverrideback to summary
private void logOverride(String name, Object definition)

Log if the definition is overriding something

Parameters
name:String

what is being defined

definition:Object

what should be null if you don't want a warning

newParallelback to summary
private Parallel newParallel(long parallelTimeout)

Create a newly bound parallel instance

Parameters
parallelTimeout:long

timeout

Returns:Parallel

a bound and initialised parallel instance.

newParallelback to summary
private Parallel newParallel(long parallelTimeout, Task child)

Create a newly bound parallel instance with one child

Parameters
parallelTimeout:long

timeout

child:Task

task

Returns:Parallel

a bound and initialised parallel instance.

processExceptionsback to summary
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
setFailOnTeardownErrorsback to summary
public void setFailOnTeardownErrors(boolean failOnTeardownErrors)

Set the failOnTeardownErrors attribute.

Parameters
failOnTeardownErrors:boolean

the value to use.

setFailureMessageback to summary
public void setFailureMessage(String failureMessage)

Set the failureMessage attribute.

Parameters
failureMessage:String

the value to use.

setFailurePropertyback to summary
public void setFailureProperty(String failureProperty)

Set the failureProperty attribute.

Parameters
failureProperty:String

the value to use.

setShutdownTimeback to summary
public void setShutdownTime(long shutdownTime)

Set the shutdownTime attribute.

Parameters
shutdownTime:long

the value to use.

setShutdownUnitback to summary
public void setShutdownUnit(WaitFor.Unit unit)

Set the shutdownunit attribute.

Parameters
unit:WaitFor.Unit

the value to use.

setTimeoutback to summary
public void setTimeout(long timeout)

Set the timeout attribute.

Parameters
timeout:long

the value to use.

setTimeoutUnitback to summary
public void setTimeoutUnit(WaitFor.Unit unit)

Set the timeoutunit attribute.

Parameters
unit:WaitFor.Unit

the value to use.

validateTaskback to summary
private void validateTask(Task task, String role)

Add any task validation needed to ensure internal code quality

Parameters
task:Task

task

role:String

role of the task

org.apache.tools.ant.taskdefs.optional.testing back to summary

private Class Funtest.NestedCondition

extends ConditionBase
implements Condition
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.condition.Condition

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
eval()

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Is this condition true?
Inherited from org.apache.tools.ant.taskdefs.condition.ConditionBase:
addaddAndaddAvailableaddChecksumaddContainsaddEqualsaddFilesMatchaddHttpaddIsFalseaddIsFileSelectedaddIsReferenceaddIsSetaddIsTrueaddNotaddOraddOsaddSocketaddUptodatecountConditionsgetConditionsgetTaskNamesetTaskName

Constructor Detail

NestedConditionback to summary
private NestedCondition()

Method Detail

evalback to summary
public boolean eval()

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Doc from org.apache.tools.ant.taskdefs.condition.Condition.eval.

Is this condition true?

Returns:boolean

true if the condition is true

Annotations
@Override