Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

junit: Cleaning up resources

Thread view: 
Maciej - 06 Oct 2006 13:22 GMT
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
richnjones@gmail.com - 06 Oct 2006 14:41 GMT
Try over-riding tearDown()

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

Richard

> Hi!
>
[quoted text clipped - 15 lines]
>
> Maciej
John - 06 Oct 2006 17:41 GMT
> Try over-riding tearDown()
>
[quoted text clipped - 25 lines]
> >
> > Maciej

In JUnit4, you can use the @After annotation.

John
Maciej - 08 Oct 2006 23:24 GMT
Thank you to all of you.
Sebastian Millies - 09 Oct 2006 09:22 GMT
Am 6 Oct 2006 09:41:33 -0700 schrieb John:

>> Try over-riding tearDown()
>>
[quoted text clipped - 9 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.