junit: Cleaning up resources

M

Maciej

Hi!

When I'm writing single test, it may fail() at any moment of the test.
Since I create some resources in the database in the begining of the
test, I'd like to remove them whenever the test finished (not matter
whether with success or not). Thus I'm looking for an approach like

try {
// init resources,
// test,
} finally {
// clean up resource
},

which handle with cleaning up: but for JUnit. Any idea?

Regards,

Maciej
 
R

richnjones

Try over-riding tearDown()

@Override
protected void tearDown() throws Exception {
super.tearDown();
//your code here*****
}

Richard
 
J

John

Try over-riding tearDown()

@Override
protected void tearDown() throws Exception {
super.tearDown();
//your code here*****
}

Richard

In JUnit4, you can use the @After annotation.

John
 
S

Sebastian Millies

Am 6 Oct 2006 09:41:33 -0700 schrieb John:
In JUnit4, you can use the @After annotation.

John

In DB testing it sometimes makes sense to re-use the connection over
all the tests. Unfortunately, in JUnit 4 a method to be annotated
with @AfterClass must be static, which makes it unsuitable to release
a connection in a test case instance. Why this restriction? Any way
round it?

-- Sebastian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top