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

Constructor Index

 o TestCase()

Method Index

 o afterTest()
Called after the tests in a Test have been called.
 o assert(boolean)
Asserts that the boolean expression is true.
 o assert(boolean, String)
Asserts that the boolean expression is true.
 o beforeTest()
Called before the tests in a Test are called.
 o getChildTests()
Lists all the child tests if any.
 o getTestContext()
Returns the TextContext, which should never be null.
 o getTestInfo()
Returns the TestInfo, which should never be null.
 o isContainer()
Indicates if the test is a container with children or no children.
 o runTest()
This is your golden opportunity to run the tests you desire.
 o setAssertDescription(String)
Sets the description to be used if an AssertFailureException is thrown.
 o setTestContext(TestContext)
Sets the context for the Test.
 o setTestInfo(TestInfo)
Sets the TestInfo the Test uses to publish information about itself.

Constructors

 o TestCase
 public TestCase()

Methods

 o 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.

 o getTestContext
 public TestContext getTestContext()
Returns the TextContext, which should never be null.

 o setTestInfo
 public void setTestInfo(TestInfo testInfo)
Sets the TestInfo the Test uses to publish information about itself.

 o getTestInfo
 public TestInfo getTestInfo()
Returns the TestInfo, which should never be null.

 o 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".

 o runTest
 public void runTest()
This is your golden opportunity to run the tests you desire.

The implementation is a "do nothing".

 o 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".

 o 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.

 o 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.
 o 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
 o 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
 o 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