org.callbackparams.junit3
Class CallbackTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.callbackparams.junit3.CallbackTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class CallbackTestCase
extends junit.framework.TestCase

Parameterized tests for JUnit-3.8.x can be created by subclassing this class instead of TestCase.
Upgrade to JUnit-4.x and usage of CallbackParamsRunner is strongly recommended! However, that does not necessarily mean quit using the JUnit-3.x API since JUnit-4.x is backward compatible and CallbackParamsRunner also can run JUnit-3.x tests.

Thou somewhat ugly, having the test-class subclass this class does not conflict with using CallbackParamsRunner to run the test. The only differences would be occasionally better performance and that only @ParameterizedCallback-annotated fields are callback-injected while the alternative combine API that is unlocked by overriding getCallbackRecords() or getCallbackRecordsFactory() would still be available.

Author:
Henrik Kaipe

Constructor Summary
protected CallbackTestCase()
           
protected CallbackTestCase(String name)
           
 
Method Summary
 int countTestCases()
           
protected  Collection getCallbackRecords()
          Returns a collection of callback-records, i.e.
protected  CallbackRecordsFactory getCallbackRecordsFactory()
          Returns the CallbackRecordsFactory instance that will be used by the default implementation of getCallbackRecords() to create the callback-records.
 void run(junit.framework.TestResult result)
           
 void testSpecialDummyTestMethodThatIsUsedToTrickJunitOnly()
          Dummy test-method that does nothing.
 
Methods inherited from class junit.framework.TestCase
createResult, getName, run, runBare, runTest, setName, setUp, tearDown, 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, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CallbackTestCase

protected CallbackTestCase(String name)

CallbackTestCase

protected CallbackTestCase()
Method Detail

testSpecialDummyTestMethodThatIsUsedToTrickJunitOnly

public final void testSpecialDummyTestMethodThatIsUsedToTrickJunitOnly()
Dummy test-method that does nothing. When the test-runner tries to run this test it is intercepted by the callback framework and test-methods with callback parameters are run instead.


run

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

countTestCases

public int countTestCases()
Specified by:
countTestCases in interface junit.framework.Test
Overrides:
countTestCases in class junit.framework.TestCase

getCallbackRecords

protected Collection getCallbackRecords()
Returns a collection of callback-records, i.e. Object[] or Collection instances that contain all callback-values for a particular test-run. This method can be overridden to test specific callback-records.
The default implementation uses the CallbackRecordsFactory supplied by the overridable method getCallbackRecordsFactory() to create the callback-records.

Please note that overriding this method is a non-static and JDK-1.4 compatible alternative to the using the annotation @CallbackRecords.

See Also:
@CallbackRecords

getCallbackRecordsFactory

protected CallbackRecordsFactory getCallbackRecordsFactory()
Returns the CallbackRecordsFactory instance that will be used by the default implementation of getCallbackRecords() to create the callback-records. The default CallbackRecordsFactory instance returned is the one supplied by the factory method CallbackRecordsFactory.getInstance(). If this default factory won't fit your purposes you can override this method.
Overriding this method is a particularly interesting alternative if you are stuck with JDK-1.4 and therefore cannot use annotations to instruct the default factory. E.g. you could then have your factory implementation override the method CallbackRecordsFactory.retrieveCombineStrategy(Class) and let it return a CombineCompletely instance instead of the default CombineAllPossible2Combinations instance.

Overriding this method is a non-static and JDK-1.4 compatible alternative to configuring a combine-strategy by using the annotation @CombineConfig. An interesting JDK-1.4 oppertunity is to override CallbackRecordsFactory.isCallbackValuesFactoryClass(java.lang.Class) and CallbackRecordsFactory.retrieveCombinedArray(java.lang.Class), e.g. to make it recognize Enum-classes a'la commons-lang ...

See Also:
CallbackRecordsFactory.retrieveCombineStrategy(java.lang.Class), CallbackRecordsFactory.retrieveCombinedArray(java.lang.Class), CallbackRecordsFactory.isCallbackValuesFactoryClass(java.lang.Class), CombineStrategy, @CombineConfig


Copyright © 2010-2013 Henrik Kaipe. All Rights Reserved.