consciouscode.junit
Class SharedFixtureTestSuite

java.lang.Object
  extended by junit.framework.TestSuite
      extended by consciouscode.junit.TestSuite
          extended by consciouscode.junit.SharedFixtureTestSuite
All Implemented Interfaces:
SharedFixtureTest, junit.framework.Test

public class SharedFixtureTestSuite
extends TestSuite
implements SharedFixtureTest

A JUnit TestSuite that provides a shared fixture for its collected Tests. This class's setUp() method is called once before any of the collected tests are run, and the tearDown() method is called once after the tests are done running.


Constructor Summary
SharedFixtureTestSuite()
           
SharedFixtureTestSuite(Class<?> theClass)
          Constructs a TestSuite from the given class.
SharedFixtureTestSuite(String name)
          Constructs an empty TestSuite.
 
Method Summary
 void addTestSuite(Class testClass)
          Adds a given TestSuite to this suite, or generates a new suite from a given class.
protected  Object getSharedFixture()
          Determine the shared fixture object that is passed to the collected tests.
 void run(junit.framework.TestResult result)
           
 void runCollectedTests(junit.framework.TestResult result)
           
 void runTest(junit.framework.Test test, junit.framework.TestResult result)
           
 void setSharedFixture(Object fixture)
          Set the shared fixture object shared by all tests within a SharedFixtureTestSuite.
protected  void setUp()
          Sets up the shared fixture for the collected tests.
protected  void tearDown()
          Tears down the shared fixture, for example, close a network connection.
 
Methods inherited from class consciouscode.junit.TestSuite
classExtendsTestSuite
 
Methods inherited from class junit.framework.TestSuite
addTest, countTestCases, createTest, getName, getTestConstructor, setName, testAt, testCount, tests, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface junit.framework.Test
countTestCases
 

Constructor Detail

SharedFixtureTestSuite

public SharedFixtureTestSuite()

SharedFixtureTestSuite

public SharedFixtureTestSuite(Class<?> theClass)
Constructs a TestSuite from the given class. Adds all the methods starting with "test" as test cases to the suite.


SharedFixtureTestSuite

public SharedFixtureTestSuite(String name)
Constructs an empty TestSuite.

Method Detail

addTestSuite

public void addTestSuite(Class testClass)
Description copied from class: TestSuite
Adds a given TestSuite to this suite, or generates a new suite from a given class. If suiteClass is a subclass of junit.framework.TestSuite, then its public no-argument constructor is called, and the resulting instance is added to this suite. Otherwise, it is passed to the superclass implementation, which will attempt to generate a TestSuite from all the methods starting with "test" that take no arguments.

Overrides:
addTestSuite in class TestSuite
Parameters:
testClass - Must extend either TestSuite or TestCase.

run

public void run(junit.framework.TestResult result)
Specified by:
run in interface junit.framework.Test
Overrides:
run in class junit.framework.TestSuite

runTest

public void runTest(junit.framework.Test test,
                    junit.framework.TestResult result)
Overrides:
runTest in class junit.framework.TestSuite

runCollectedTests

public void runCollectedTests(junit.framework.TestResult result)

setSharedFixture

public void setSharedFixture(Object fixture)
Description copied from interface: SharedFixtureTest
Set the shared fixture object shared by all tests within a SharedFixtureTestSuite. This method is invoked by SharedFixtureTestSuite just before the test's setUp method is called.

Specified by:
setSharedFixture in interface SharedFixtureTest

getSharedFixture

protected Object getSharedFixture()
Determine the shared fixture object that is passed to the collected tests. This method is called after a successful call to setUp(), and the result is passed to the SharedFixtureTest.setSharedFixture(java.lang.Object) method (if applicable) of each collected test.

By default, the shared fixture is null; subclass suites should set the fixture in their setUp method.


setUp

protected void setUp()
              throws Exception
Sets up the shared fixture for the collected tests. This method is called before the collected tests are executed.

Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Tears down the shared fixture, for example, close a network connection. This method is called after the collected tests are executed.

This implementation simply releases the shared fixture; subclasses must call here if they override this method!

Throws:
Exception


Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.