Package ise.antelope.tasks
Class TestCase
- java.lang.Object
-
- org.apache.tools.ant.ProjectComponent
-
- org.apache.tools.ant.Task
-
- ise.antelope.tasks.TestCase
-
- All Implemented Interfaces:
java.lang.Cloneable
public class TestCase extends org.apache.tools.ant.Task
Modeled after the TestCase provided by jUnit, this class is an Ant task that looks through the build file set in thesetFile
method, calls a 'setUp' target in that build file (if it exists), then all targets whose names start with 'test', and last calls a target named 'tearDown' (if it exists). Both 'setUp' and 'tearDown' are optional targets in the build file.Ant stores targets in a hashtable, so there is no guaranteed order in which the 'test*' classes will be called. If order is important, use the 'depends' attribue of a target to enforce order, and do not name dependent targets with a name starting with 'test'.
Test targets may also be imported with the import task. Imported files should not have a "suite" task in the implicit target as such a task would rerun all test targets in all files.
- Version:
- $Revision: 138 $
-
-
Constructor Summary
Constructors Constructor Description TestCase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute()
Run tests.int
getFailedCount()
java.util.Enumeration
getFailures()
java.lang.String
getName()
int
getPassedCount()
int
getRanCount()
java.lang.String
getSummary()
Gets the summary attribute of the TestCase objectint
getTestCaseCount()
int
getWarningCount()
void
init()
task initilizationvoid
setAssertsenabled(boolean b)
Should Asserts be enabled? Many (most?) tests will use the Assert task, which requires a property to be set to actually enable the asserts.void
setEnabled(boolean b)
void
setFailonerror(boolean b)
Should the build fail if the test fails? By default, a failed test does not cause the build to fail, so all tests may have the opportunity to run.void
setFile(java.io.File f)
void
setName(java.lang.String n)
Set the name for this testcase.void
setShowoutput(boolean b)
void
setShowsummary(boolean b)
-
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
-
-
-
-
Method Detail
-
init
public void init()
task initilization- Overrides:
init
in classorg.apache.tools.ant.Task
-
getTestCaseCount
public int getTestCaseCount()
- Returns:
- the count of test targets.
-
getRanCount
public int getRanCount()
- Returns:
- the number of tests targets actually executed.
-
getFailedCount
public int getFailedCount()
- Returns:
- the number of tests that failed.
-
getWarningCount
public int getWarningCount()
-
getPassedCount
public int getPassedCount()
- Returns:
- the number of tests that passed.
-
getFailures
public java.util.Enumeration getFailures()
- Returns:
- an Enumeration of the failures. Individual elements are Strings containing the name of the failed target and the reason why it failed.
-
setShowoutput
public void setShowoutput(boolean b)
- Parameters:
b
- if true, show the output of the tests as they run. Optional, default is true, do show output.
-
setShowsummary
public void setShowsummary(boolean b)
- Parameters:
b
- if true, show the summary output (number of tests, passed, failed) after the completion of all tests. Optional, default is true, do show summary.
-
setFile
public void setFile(java.io.File f)
- Parameters:
f
- the file containing the tests to execute. Required. The file itself is a standard Ant build file, but will be treated differently than if Ant itself ran it. If there is a target named "setUp", that target will be executed first, then all targets with names starting with "test" (not in any particular order), then if there is a target named "tearDown", that target will be executed last. All other targets are ignored.
-
setAssertsenabled
public void setAssertsenabled(boolean b)
Should Asserts be enabled? Many (most?) tests will use the Assert task, which requires a property to be set to actually enable the asserts. By default, Asserts are enabled for testcases.- Parameters:
b
- if false, do not enable asserts. Note that this sets an Ant property, and due to property immutability, this attribute may have no effect if it has been set already. Generally, asserts are enabled or disabled for an entire build.
-
setFailonerror
public void setFailonerror(boolean b)
Should the build fail if the test fails? By default, a failed test does not cause the build to fail, so all tests may have the opportunity to run.- Parameters:
b
- set to true to cause the build to fail if the test fails
-
getName
public java.lang.String getName()
- Returns:
- the name of the test as set by
setName
. If the name has not be explicitly set, then the test name is the project name if there is one, otherwise, the filename of the test file.
-
setName
public void setName(java.lang.String n)
Set the name for this testcase.- Parameters:
n
- the name for the testcase
-
setEnabled
public void setEnabled(boolean b)
- Parameters:
b
- if true, execute the test. This is handy for enabling or disabling groups of tests in a 'suite' by setting a single property. Optional, default is true, the test should run.
-
execute
public void execute()
Run tests.- Overrides:
execute
in classorg.apache.tools.ant.Task
-
getSummary
public java.lang.String getSummary()
Gets the summary attribute of the TestCase object- Returns:
- The summary value
-
-