|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
com.google.common.testing.junit3.TearDownTestCase
public abstract class TearDownTestCase
A base class for test cases that require reliable tear-down.
JUnit's concept of TestCase.tearDown()
works fine for strict "unit
tests" (which is what the authors of JUnit "want" you to write with it),
but it turns out that for anything even slightly more complex, it has
severe limitations, including:
TestCase.setUp()
,
tearDown()
will never get called
tearDown()
may not know which cleanup steps are actually needed
tearDown()
, the rest of
tearDown()
(including super.tearDown()
!) will never get
called ("obviously" -- but this is dangerous!)
tearDown()
...
tearDown()
exception will
hide the real test error
tearDown()
method, which therefore needs to try to perform the
union of all possible cleanup operations that could be needed of it.
tearDown()
methods (if they have them).
addTearDown(new TearDown() { public void tearDown() throws Exception { // cleanup logic here } });
If you are writing a piece of test infrastructure, not a test case, and
you want to be sure that what you do will be cleaned up, simply require
your caller to pass in an active instance of TearDownAccepter
, to
which you can add your TearDown
s.
Please see usage examples in TearDownTestCaseTest
.
Field Summary | |
---|---|
(package private) TearDownStack |
stack
|
Constructor Summary | |
---|---|
TearDownTestCase()
Creates a TearDownTestCase with the default (empty) name. |
|
TearDownTestCase(java.lang.String name)
Creates a TearDownTestCase with the specified name. |
Method Summary | |
---|---|
void |
addTearDown(TearDown tearDown)
Registers a TearDown implementor which will be run during tearDown() |
void |
runBare()
|
protected void |
setUp()
|
protected void |
tearDown()
|
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runTest, setName, 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 |
Field Detail |
---|
final TearDownStack stack
Constructor Detail |
---|
public TearDownTestCase()
public TearDownTestCase(java.lang.String name)
Method Detail |
---|
protected void setUp() throws java.lang.Exception
setUp
in class junit.framework.TestCase
java.lang.Exception
public final void addTearDown(TearDown tearDown)
tearDown()
addTearDown
in interface TearDownAccepter
protected final void tearDown()
tearDown
in class junit.framework.TestCase
public final void runBare() throws java.lang.Throwable
runBare
in class junit.framework.TestCase
java.lang.Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |