• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JUnit and SQL isolation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what about TestCase.getName() ?
 
christophe seguinot
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic