aspose file tools*
The moose likes Testing and the fly likes JUnit and SQL isolation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit and SQL isolation" Watch "JUnit and SQL isolation" New topic
Author

JUnit and SQL isolation

christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
Hello,

I would like each test method of the test case to have its own data.

Here is what we are currently doing :
- before each test the database is created
- the sql is inserted in the database (hsqldb or oracle)
- the test method is executed
- the database is dropped

We are going through this loop for all methods in the test case.

As a consequence the file which contains the sql statement contains the SQL needed by all the methods of the test case. This is cumbersom especially when methods are closely related. (assertEquals(1, list.size()) -> assertEquals(2, list.size() for example)

Instead, I would like to have an sql file for each method. To do this I must be able to know what is the method which is going to be executed by JUnit. And I have no idea on how to retreive this value.

Does anyone know how to do this ? or maybe a better idea to isolate the sql between methods ?

Thanks a lot,

Best Regards,

Chris
enric jaen
Greenhorn

Joined: Oct 15, 2010
Posts: 25
what about TestCase.getName() ?
christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
We are using junit 3.8 and TestCase.getName() is not defined. Thanks by the way.
enric jaen
Greenhorn

Joined: Oct 15, 2010
Posts: 25
but getName() is defined in 3.8.1 [1] Maybe you meant 4.0? If so, you can use this: http://stackoverflow.com/questions/473401/get-name-of-currently-executing-test-in-junit-4

or try accessing directly in Java: http://www.kodejava.org/examples/482.html

[1] http://www.junit.org/junit/javadoc/3.8.1/junit/framework/TestCase.html

Hope this helps
christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
Thanks a lot, the whole mechanism is now working using TestCase.getName(). I was trying to access a static method instead of doing this.getName(). Thanks for you patience.
Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit and SQL isolation