junitx.ddtunit
Class DDTTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by groovy.util.GroovyTestCase
              extended by junitx.ddtunit.DDTTestCase
All Implemented Interfaces:
junit.framework.Test, IDDTTestCase

public abstract class DDTTestCase
extends groovy.util.GroovyTestCase
implements IDDTTestCase

This class is derived from TestCasefrom JUnit.
It will implement all neccessary features to run tests based on xml parameter data.

Author:
jg

Field Summary
 
Fields inherited from class groovy.util.GroovyTestCase
TEST_SCRIPT_NAME_PREFIX
 
Constructor Summary
DDTTestCase()
           
DDTTestCase(String name)
           
 
Method Summary
protected  void addObjectToAssert(String assertId, Object object)
          Add object to make assertion against assert definition identified by assertId
protected  void assertObject(String assertId, Object obj)
          Directly assert expected against actual object during method execution.
protected  void assertObject(String assertId, Object obj, boolean mark)
          Directly assert expected against actual object during method execution.
 int countMethodTests()
          Count number of test datasets provided for method methodName.
protected  Object getGlobalObject(String objectId)
          Retrieve object with specified identifier on a per class basis.
protected  Object getGlobalObject(String objectId, String objectType)
          Retrieve object with specified identifier on a per class basis.
protected  Object getObject(String objectId)
          Retrieve object with specified identifier on a per method-test basis.
protected  Object getObject(String objectId, String objectType)
          Retrieve object with specified identifier on a per method-test basis.
protected  Object getResourceObject(String objectId)
          Retrieve object with specified identifier on class independend basis.
protected  Object getResourceObject(String objectId, String objectType)
          Retrieve object with specified identifier on class independend basis.
 String getTestName()
           
protected abstract  void initContext()
          Implement method for initializing test context.
protected  void initTestData(String classId)
          Initialize xml test data for specified classId in resource associagted to same name as classId using ResourceNameFactory.
protected  void initTestData(String resource, String classId)
          Initialize xml test data for specified classId in resource
 junit.framework.TestResult run()
          Run complete selected testmethod by generating a separate result und return this after execution.
 void run(junit.framework.TestResult result)
          Run complete selected testmethod by generating a separate result und return this after execution.
 void runBare()
          Run a bare method cycle as defined in JUnit.
 String runInfo()
           
protected  void runMethodTest()
          Execute the testmethod without extra setUp and tearDown methods and no hooks to TestListener classes like TestRunner.
protected  void runTest()
          Do not use this method to define tests.
 void setTestName(String testName)
           
protected  void validateAsserts(boolean assertSupport)
          Validate all assertions concerning the active method-test dataset.
 
Methods inherited from class groovy.util.GroovyTestCase
assertArrayEquals, assertContains, assertContains, assertEquals, assertEquals, assertEquals, assertInspect, assertLength, assertLength, assertLength, assertScript, assertToString, fixEOLs, getMethodName, getName, getTestClassName, notYetImplemented, notYetImplemented, shouldFail, shouldFail, shouldFailWithCause
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, 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, 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
 
Methods inherited from interface junitx.ddtunit.IDDTTestCase
getName
 

Constructor Detail

DDTTestCase

public DDTTestCase()

DDTTestCase

public DDTTestCase(String name)
Parameters:
name - of testmethod to execute
Method Detail

run

public junit.framework.TestResult run()
Run complete selected testmethod by generating a separate result und return this after execution. This contains all notification hooks to TestListener classes like TestRunner.

Specified by:
run in interface IDDTTestCase
Overrides:
run in class junit.framework.TestCase
Returns:
result of executed test

run

public void run(junit.framework.TestResult result)
Run complete selected testmethod by generating a separate result und return this after execution. This contains all notification hooks to TestListener classes like TestRunner.

Specified by:
run in interface junit.framework.Test
Specified by:
run in interface IDDTTestCase
Overrides:
run in class junit.framework.TestCase
Parameters:
result - object generated externally, by a testrunner e.g..

runBare

public void runBare()
             throws Throwable
Run a bare method cycle as defined in JUnit. Here the testdata initialization is performed. Because every testmethod should be run under its own fixture the execution of setUp and tearDown is inside of a subroutine. These methods will be executed inside of around every test representation of xml testdata definition.

Specified by:
runBare in interface IDDTTestCase
Overrides:
runBare in class junit.framework.TestCase
Throws:
Throwable - that might come up during testmethod execution.

getObject

protected Object getObject(String objectId)
Retrieve object with specified identifier on a per method-test basis.
If no data exists an exception will be raised.

Parameters:
objectId - specifies key for retrieval
Returns:
Object that is stored under identifier key

getObject

protected Object getObject(String objectId,
                           String objectType)
Retrieve object with specified identifier on a per method-test basis.
If no data exists an exception will be raised.

Parameters:
objectId - specifies key for retrieval
Returns:
Object that is stored under identifier key

getGlobalObject

protected Object getGlobalObject(String objectId)
Retrieve object with specified identifier on a per class basis.
If no data exists an exception will be raised.

Parameters:
objectId - specifies key for retrieval
Returns:
Object that is stored under identifier key

getGlobalObject

protected Object getGlobalObject(String objectId,
                                 String objectType)
Retrieve object with specified identifier on a per class basis.
If no data exists an exception will be raised.

Parameters:
objectId - specifies key for retrieval
Returns:
Object that is stored under identifier key

getResourceObject

protected Object getResourceObject(String objectId)
Retrieve object with specified identifier on class independend basis.
If no data exists an exception will be raised.

Parameters:
objectId - specifies key for retrieval
Returns:
Object that is stored under identifier key

getResourceObject

protected Object getResourceObject(String objectId,
                                   String objectType)
Retrieve object with specified identifier on class independend basis.
If no data exists an exception will be raised.

Parameters:
objectId - specifies key for retrieval
Returns:
Object that is stored under identifier key

addObjectToAssert

protected void addObjectToAssert(String assertId,
                                 Object object)
Add object to make assertion against assert definition identified by assertId

Parameters:
assertId - to identify assert
object - used as actual object against expected object defined in assertion

assertObject

protected void assertObject(String assertId,
                            Object obj)
Directly assert expected against actual object during method execution. Do not wait till the end of test execution.

Parameters:
assertId - to retrieve expected assert
obj - to assert against expected value

assertObject

protected void assertObject(String assertId,
                            Object obj,
                            boolean mark)
Directly assert expected against actual object during method execution. Do not wait till the end of test execution.

Parameters:
assertId - to retrieve expected assert
obj - to assert against expected value
mark - true if validation should be marked as executed

validateAsserts

protected void validateAsserts(boolean assertSupport)
Validate all assertions concerning the active method-test dataset. All asserts that are not marked as allready processed are validated and marked as processed.


initContext

protected abstract void initContext()
Implement method for initializing test context. Especially retrieving test data resource.
The easies way to do this is just to use the following code snipplet:
 void initContext() {
        initTestData("/mySpecialResource.xml", "ClassIdInResourceToUse");
 }
 


initTestData

protected void initTestData(String classId)
Initialize xml test data for specified classId in resource associagted to same name as classId using ResourceNameFactory.

Parameters:
resource - of xml based test data

initTestData

protected void initTestData(String resource,
                            String classId)
Initialize xml test data for specified classId in resource

Parameters:
resource - of xml based test data
classId - of test data to process

runTest

protected void runTest()
Do not use this method to define tests. Use test<name>() instead.

Overrides:
runTest in class junit.framework.TestCase

runMethodTest

protected void runMethodTest()
                      throws Throwable
Execute the testmethod without extra setUp and tearDown methods and no hooks to TestListener classes like TestRunner.
This method contains the iteration over the xml defined tests per method.

Throws:
Throwable - on any exception that occures

countMethodTests

public int countMethodTests()
Count number of test datasets provided for method methodName.
If dataset for this method is null, 1 will be returned (a standard JUnit method)

Specified by:
countMethodTests in interface IDDTTestCase
Returns:
Count of tests under method methodName

runInfo

public String runInfo()
Specified by:
runInfo in interface IDDTTestCase
Returns:
Information about actual run test

getTestName

public String getTestName()
Specified by:
getTestName in interface IDDTTestCase
Returns:
Returns the testName.

setTestName

public void setTestName(String testName)
Specified by:
setTestName in interface IDDTTestCase
Parameters:
testName - The testName to set.


Copyright © 2004-2011. All Rights Reserved.