org.geworkbench.bison.testing
Class BulkTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.geworkbench.bison.testing.BulkTest
All Implemented Interfaces:
java.lang.Cloneable, junit.framework.Test
Direct Known Subclasses:
CSPanelTest

public class BulkTest
extends junit.framework.TestCase
implements java.lang.Cloneable

A TestCase that can define both simple and bulk test methods.

A simple test method is the type of test traditionally supplied by by TestCase. To define a simple test, create a public no-argument method whose name starts with "test". You can specify the the name of simple test in the constructor of BulkTest; a subsequent call to TestCase.run() will run that simple test.

A bulk test method, on the other hand, returns a new instance of BulkTest, which can itself define new simple and bulk test methods. By using the makeSuite(java.lang.Class) method, you can automatically create a hierarchal suite of tests and child bulk tests.

For instance, consider the following two classes:

 public class TestSet extends BulkTest {
 

private Set set;

public TestSet(Set set) { this.set = set; }

public void testContains() { boolean r = set.contains(set.iterator().next())); assertTrue("Set should contain first element, r); }

public void testClear() { set.clear(); assertTrue("Set should be empty after clear", set.isEmpty()); } }

public class TestHashMap extends BulkTest {

private Map makeFullMap() { HashMap result = new HashMap(); result.put("1", "One"); result.put("2", "Two"); return result; }

public void testClear() { Map map = makeFullMap(); map.clear(); assertTrue("Map empty after clear", map.isEmpty()); }

public BulkTest bulkTestKeySet() { return new TestSet(makeFullMap().keySet()); }

public BulkTest bulkTestEntrySet() { return new TestSet(makeFullMap().entrySet()); } }

In the above examples, TestSet defines two simple test methods and no bulk test methods; TestHashMap defines one simple test method and two bulk test methods. When makeSuite(TestHashMap.class).run is executed, five simple test methods will be run, in this order:

  1. TestHashMap.testClear()
  2. TestHashMap.bulkTestKeySet().testContains();
  3. TestHashMap.bulkTestKeySet().testClear();
  4. TestHashMap.bulkTestEntrySet().testContains();
  5. TestHashMap.bulkTestEntrySet().testClear();

In the graphical junit test runners, the tests would be displayed in the following tree:

A subclass can override a superclass's bulk test by returning null from the bulk test method. If you only want to override specific simple tests within a bulk test, use the ignoredTests() method.

Note that if you want to use the bulk test methods, you must define your suite() method to use makeSuite(java.lang.Class). The ordinary TestSuite constructor doesn't know how to interpret bulk test methods.

Version:
$Id: BulkTest.java,v 1.6 2006-09-13 19:09:57 watkinson Exp $
Author:
Matt Hall, John Watkinson, Paul Jack

Constructor Summary
BulkTest(java.lang.String name)
          Constructs a new BulkTest instance that will run the specified simple test.
 
Method Summary
 java.lang.Object clone()
          Creates a clone of this BulkTest.
 java.lang.String[] ignoredTests()
          Returns an array of test names to ignore.
static junit.framework.TestSuite makeSuite(java.lang.Class c)
          Returns a TestSuite for testing all of the simple tests and all the bulk tests defined by the given class.
 java.lang.String toString()
          Returns the display name of this BulkTest.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BulkTest

public BulkTest(java.lang.String name)
Constructs a new BulkTest instance that will run the specified simple test.

Parameters:
name - the name of the simple test method to run
Method Detail

clone

public java.lang.Object clone()
Creates a clone of this BulkTest.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this BulkTest

ignoredTests

public java.lang.String[] ignoredTests()
Returns an array of test names to ignore.

If a test that's defined by this BulkTest or by one of its bulk test methods has a name that's in the returned array, then that simple test will not be executed.

A test's name is formed by taking the class name of the root BulkTest, eliminating the package name, then appending the names of any bulk test methods that were invoked to get to the simple test, and then appending the simple test method name. The method names are delimited by periods:

  TestHashMap.bulkTestEntrySet.testClear
  

is the name of one of the simple tests defined in the sample classes described above. If the sample TestHashMap class included this method:

  public String[] ignoredTests() {
      return new String[] { "TestHashMap.bulkTestEntrySet.testClear" };
  }
  

then the entry set's clear method wouldn't be tested, but the key set's clear method would.

Returns:
an array of the names of tests to ignore, or null if no tests should be ignored

toString

public java.lang.String toString()
Returns the display name of this BulkTest.

Overrides:
toString in class junit.framework.TestCase
Returns:
the display name of this BulkTest

makeSuite

public static junit.framework.TestSuite makeSuite(java.lang.Class c)
Returns a TestSuite for testing all of the simple tests and all the bulk tests defined by the given class.

The class is examined for simple and bulk test methods; any child bulk tests are also examined recursively; and the results are stored in a hierarchal TestSuite.

The given class must be a subclass of BulkTest and must not be abstract.

Parameters:
c - the class to examine for simple and bulk tests
Returns:
a TestSuite containing all the simple and bulk tests defined by that class