Class TestWithCustomTest

java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.castor.xmlctf.TestWithCustomTest
All Implemented Interfaces:
junit.framework.Test

class TestWithCustomTest extends junit.framework.TestCase
Implements a test case that tests code written by the XML source generator. This class uses a user-provided test class to test the generated source.

Each user-provided test is allowed to return a Boolean, either a primitive or a java.lang.Boolean -- it does not matter. If the user-provided test returns a Boolean and it is false, then the test is considered to have failed. If the user-provided test throws or returns a Throwable, it is considered to have failed. If the user-provided test returns anything else (including void) then the test is considered to have passed.

Note: Returning Throwable is a little bit cleaner than throwing an Exception, but either is acceptable as a sign of test failure. This is because when a Throwable is returned, if -printStack is in effect, then the CORRECT stack trace can be displayed and not a stack dump from the refective invocation.

There is no requirement that the user-provided test implement any interface, nor any requirement that the user-provided test return anything at all. However, a test that returns "void" and that never throws an Exception is not a very useful test as it can never fail.

Version:
$Revision: 0000 $ $Date: $
Author:
Edward Kuns
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final FailureType
    The failure object that is not null is the test intends to fail.
    protected final boolean
    True if the test is supposed to return failure or throw an Exception.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Blank constructor for this test case.
    Constructs a test case that when invoked will delegate to the provided test case.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
    getTestObject(String testClassName)
    Gets an instance of our test object, as configured.
    void
    Runs our test case using our delegate object where necessary.
    protected void
    Provides setup for our delegated test case, depending on the type of test case we are delegating for.
    protected void
    Provides tear down for our delegated test case, depending on the type of test case we are delegating for.

    Methods inherited from class junit.framework.TestCase

    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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, setName, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • _failure

      protected final FailureType _failure
      The failure object that is not null is the test intends to fail.
    • _failureExpected

      protected final boolean _failureExpected
      True if the test is supposed to return failure or throw an Exception.
  • Constructor Details

    • TestWithCustomTest

      TestWithCustomTest(String name)
      Blank constructor for this test case. This contructor is not useful, since no delegate test case is provided.
      Parameters:
      name - Name of our delegate test case
    • TestWithCustomTest

      TestWithCustomTest(String name, XMLTestCase tc)
      Constructs a test case that when invoked will delegate to the provided test case.
      Parameters:
      name - Name of our delegate test case
      tc -
  • Method Details

    • setUp

      protected void setUp() throws Exception
      Provides setup for our delegated test case, depending on the type of test case we are delegating for.
      Overrides:
      setUp in class junit.framework.TestCase
      Throws:
      Exception - if anything goes wrong during setup
    • tearDown

      protected void tearDown() throws Exception
      Provides tear down for our delegated test case, depending on the type of test case we are delegating for.
      Overrides:
      tearDown in class junit.framework.TestCase
      Throws:
      Exception - if anything goes wrong during teardown
    • runTest

      public void runTest()
      Runs our test case using our delegate object where necessary.
      Overrides:
      runTest in class junit.framework.TestCase
      Throws:
      Exception - when anything goes wrong (this is temporary)
    • getTestObject

      protected Object getTestObject(String testClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException
      Gets an instance of our test object, as configured.
      Parameters:
      testClassName - name of the test class
      Returns:
      an instance of our test object
      Throws:
      ClassNotFoundException - when the test object's class cannot be found
      IllegalAccessException - when the test object's constructor is private or protected
      InstantiationException - when the test object is abstract or an interface