Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit and SQL isolation

 
christophe seguinot
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about TestCase.getName() ?
 
christophe seguinot
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are using junit 3.8 and TestCase.getName() is not defined. Thanks by the way.
 
enric jaen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic