All Packages Class Hierarchy This Package Previous Next Index
Class org.ajug.jsl.jester.cases.TestCase
java.lang.Object
|
+----org.ajug.jsl.jester.cases.TestCase
- public class TestCase
- extends Object
- implements Test
This class is subclassed by nearly all tests. It provides default
implementations for all methods in Test. The subclass should
override these as needed, except for the assert related methods.
For example "containers" absolutely must override
isContainer() and getChildTests().
This class adds convenience methods such as assert(boolean isTrue).
Here's an example of a simple container test:
public class MathTest extends TestCase {
private Vector children;
public boolean isContainer() {
return true;
}
public Enumeration getChildTests() {
if (children == null) {
children = new Vector();
children.addElement(new MathLibTest());
children.addElement(new IntegrandTest());
children.addElement(new FourierTest());
}
return children.elements();
}
public void beforeTest() {
testContext.addProperty(new Property("Offset", 1));
}
}
Here's an example of a simple leaf test. Notice how it uses
the "Offset" property provided by MathTest above. MathTest could also
have provided a reference to the library to test, or any such
environmental data its child test need to run a coordinated carefully
designed test. Note that runTest() is called between
beforeTest() and afterTest().
public class MathLibTest extends TestCase {
private MathLib library;
public void beforeTest() {
library = new MathLib(1);
}
public void runTest() {
int offset = testContext.getInt("Offset");
assert(library.getOffset() == offset);
assert(library.getCoolConstant() == 3.14156);
}
public void afterTest() {
library.close();
}
}
- See Also:
- Test
-
TestCase()
-
-
afterTest()
- Called after the tests in a Test have been called.
-
assert(boolean)
- Asserts that the boolean expression is true.
-
assert(boolean,
String)
- Asserts that the boolean expression is true.
-
beforeTest()
- Called before the tests in a Test are called.
-
getChildTests()
- Lists all the child tests if any.
-
getTestContext()
- Returns the TextContext, which should never be null.
-
getTestInfo()
- Returns the TestInfo, which should never be null.
-
isContainer()
- Indicates if the test is a container with children or no children.
-
runTest()
- This is your golden opportunity to run the tests you desire.
-
setAssertDescription(String)
- Sets the description to be used if an AssertFailureException
is thrown.
-
setTestContext(TestContext)
-
Sets the context for the Test.
-
setTestInfo(TestInfo)
- Sets the TestInfo the Test uses to publish information about
itself.
TestCase
public TestCase()
setTestContext
public void setTestContext(TestContext testContext)
- Sets the context for the Test. The context is the only way the
test can reach the outside world, the main purpose of the
Context Pattern. Each test has its own unique context, which
cannot be null.
If the test sets properties this must be done within
this method. This allows passing container properties to their
children before a test's beforeTest() is called.
getTestContext
public TestContext getTestContext()
- Returns the TextContext, which should never be null.
setTestInfo
public void setTestInfo(TestInfo testInfo)
- Sets the TestInfo the Test uses to publish information about
itself.
getTestInfo
public TestInfo getTestInfo()
- Returns the TestInfo, which should never be null.
beforeTest
public void beforeTest()
- Called before the tests in a Test are called. This is an
opportunity to set up test fixtures.
The implementation is a "do nothing".
runTest
public void runTest()
- This is your golden opportunity to run the tests you desire.
The implementation is a "do nothing".
afterTest
public void afterTest()
- Called after the tests in a Test have been called. Any
outstanding resources should be released.
The implementation is a "do nothing".
isContainer
public boolean isContainer()
- Indicates if the test is a container with children or no children.
The testing framework uses the terminology of "containers" and
"leafs", A Test may be either, allows great flexiblity and a far
more simple, lightweight framework.
The implementation returns a default value of false.
getChildTests
public Enumeration getChildTests()
- Lists all the child tests if any. If isContainer() returns false
then this method is never called. To speed testing the
implementation should wait until the first time this method is
called to create the child tests and the collection they are
stored in. This method can be called multiple times at any time.
The implementation returns a default value of null.
- Returns:
- an enumeration of objects implementating Test. They will
be run in the order provided. For each call they must be the
same instances. If a leaf then returns null.
assert
public void assert(boolean isTrue)
- Asserts that the boolean expression is true. If true it does
nothing. If false an AssertFailureException is thrown
containing the description. The description overrides the
other one provided in
setAssertDescription(String),
if any.
- See Also:
- setAssertDescription
assert
public void assert(boolean isTrue,
String description)
- Asserts that the boolean expression is true. If true it does
nothing. If false an AssertFailureException is thrown
containing the description. The description overrides the
other one provided in
setAssertDescription(String),
if any.
- See Also:
- setAssertDescription
setAssertDescription
public void setAssertDescription(String description)
- Sets the description to be used if an AssertFailureException
is thrown. The description remains in effect until reset or
set to null.
- See Also:
- assert
All Packages Class Hierarchy This Package Previous Next Index