|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase
A subclass of TestCase to ease the requirements of creating an interface test. The tests should be thought of as "contract tests". Subclasses can call createImplObject() to create a new instance of a subclass of interfaceClass, which is generated from the ImplFactory passed into the constructor.
Subclasses that want to use the InterfaceTestSuite helper class will need to specify a constructor similar to:
public MyClassTest( String name, ImplFactory f ) { super( name, MyClass.class, f ); }where MyClass is the interface or base class under test.
As of October 30, 2002, the InterfaceTestCase has a slightly different behavior when the factory instance is an implementation of ICxFactory. In this scenario, it will store all the instantiated objects in the stack, and each instantiated object will be passed to the ICxFactory instance during the test's normal tearDown. If the ICxFactory throws an exception during any of the tearDown calls, they will be stored up and reported in a single exception. Therefore, if you want this functionality, then you will need to ensure that your tearDown() method calls the super tearDown().
Even though JUnit 3.8+ allows for a TestCase to have a default (no-arg) constructor, the InterfaceTestCase does not support this. The benefits simply aren't there for interface tests: they will still have to create a constructor which passes InterfaceTestCase which class is being tested. Since a constructor is required anyway, the little extra effort to add two arguments to the constructor and call to the super is trivial compared to not needing the constructor at all.
As of 08-Dec-2002, the returned name of the test can include the class's name, without the package, to improve traceability. This will allow the user to be able to see in which specific test class an error occured through the Ant JUnit report mechanism. This is enabled by default, but can be disabled by setting the Java system-wide property "net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase.no-classname" to true, which is dynamically checked at runtime at each call.
ImplFactory
,
ICxFactory
,
InterfaceTestSuite
Constructor Summary | |
InterfaceTestCase(java.lang.String name,
java.lang.Class interfaceClass,
ImplFactory f)
The standard constructor used by JUnit up to version 3.7. |
Method Summary | |
java.lang.Object |
createImplObject()
Calls the stored factory to create an implemented object. |
java.lang.Class |
getInterfaceClass()
Return the interface or abstract class this test covers. |
java.lang.String |
getName()
Override the TestCase default getName so that the factory names are returned as well. |
java.lang.String |
name()
Ensure, for JUnit 3.7 support, that the original name() method is still supported. |
void |
setUseClassInName(boolean use)
Sets whether the classname is put in the output or not. |
protected void |
tearDown()
Send each instantiated object to the factory for cleanup. |
Methods inherited from class junit.framework.TestCase |
countTestCases, createResult, run, run, runBare, runTest, setName, setUp, 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 |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public InterfaceTestCase(java.lang.String name, java.lang.Class interfaceClass, ImplFactory f)
name
- the name of the test to execute.interfaceClass
- the class which this test case tests.f
- the factory which will create specific subclass instances.Method Detail |
public void setUseClassInName(boolean use)
public java.lang.Object createImplObject()
This method makes an assertion that the factory's created object is not null, so that the system state is ensured. Therefore, this method will never return null. Also, this method asserts that the created object is of the correct type (as passed in through the constructor), so that it can be correctly cast without errors.
public java.lang.Class getInterfaceClass()
public java.lang.String getName()
public java.lang.String name()
protected void tearDown() throws java.lang.Exception
java.lang.Exception
- thrown if the super's tearDown throws an
exception, or if any exceptions are thrown during the tear-down
of the factory generated instances.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |