org.opensubsystems.core.persist.db
Class DatabaseTestSetup

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.extensions.TestDecorator
          extended by junit.extensions.TestSetup
              extended by org.opensubsystems.core.persist.db.DatabaseTestSetup
All Implemented Interfaces:
junit.framework.Test

public class DatabaseTestSetup
extends junit.extensions.TestSetup

This class makes sure that the database is propertly initialized before the tests are executed and that the database is properly shutdown when all tests are finished. ALL TESTCASES DERIVED FROM DatabaseTest CLASS AND ALL TEST SUITES INCLUDING SUCH TEST CASES SHOULD FOLLOW THE DIRECTION BELLOW. To use this setup in your class define your tests as class MyTest { public static Test suite( ) { TestSuite suite = new DatabaseTestSuite("MyTest"); suite.addTestSuite(MyTestInternal.class); TestSetup wrapper = new DatabaseTestSetup(suite); return wrapper; } public static class MyTestInternal extends TestCase { // add tests here } } This way if the top level test gets executed, it will be executed as a suite and this setup will be invoked for all tests in the suite and therefore database will be properly initialized and shutdown. If you want to include these tests in another suite, DO NOT ADD MyTest but instead add MyTest.MyTestInternal. This way the suite which includes this test can invoke the setup once for all included tests. To create a suite of suites, define your suite as public final class MyTests { public static Test suite( ) { TestSuite suite = new DatabaseTestSuite("My tests"); addGenericTests(suite); TestSetup wrapper = new DatabaseTestSetup(suite); return wrapper; } public static void addGenericTests( TestSuite suite ) { // Here we are adding single test case class using the inner internal class suite.addTestSuite(MyTestInternal.class); // Here we are including tests from another suite without including the // DatabaseTestSetup again MyOtherTests.addGenericTests(suite); } }

Version:
$Id: DatabaseTestSetup.java,v 1.3 2007/01/07 06:14:20 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Code reviewed:
TODO: Review this code

Field Summary
protected static java.lang.String DEFAULT_PROPERTY_FILE
          Default property file used to run tests.
 
Fields inherited from class junit.extensions.TestDecorator
fTest
 
Constructor Summary
DatabaseTestSetup(junit.framework.Test test)
          Create new DatabaseTestSetup.
 
Method Summary
protected  void setUp()
          Set up environment for the test cases.
protected  void tearDown()
          Restore original environment after all the tests were run.
 
Methods inherited from class junit.extensions.TestSetup
run
 
Methods inherited from class junit.extensions.TestDecorator
basicRun, countTestCases, getTest, toString
 
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, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PROPERTY_FILE

protected static final java.lang.String DEFAULT_PROPERTY_FILE
Default property file used to run tests.

See Also:
Constant Field Values
Constructor Detail

DatabaseTestSetup

public DatabaseTestSetup(junit.framework.Test test)
Create new DatabaseTestSetup.

Parameters:
test - - test to run
Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
Set up environment for the test cases.

Overrides:
setUp in class junit.extensions.TestSetup
Throws:
java.lang.Exception - - an error has occured while setting up tests

tearDown

protected void tearDown()
                 throws java.lang.Exception
Restore original environment after all the tests were run.

Overrides:
tearDown in class junit.extensions.TestSetup
Throws:
java.lang.Exception - - an error has occured while tearing down tests


Copyright © 2003 - 2006 OpenSubsystems s.r.o.