• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

DBUnit best practice

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I wish to know how to use DBUnit 2.5 to test database access.
1. In PROD, I use Oracle, surely that doesn't mean I have to use Oracle for unit testing right? I'm assuming HSQLDB is good enough. is it possible to use HSQLDB to mock Oracle? I mean so that HSQLDB can process Oracle's syntax?
2. Which class to extend when writing test classes? xxxTestCase or xxxDatabaseTester?
3. What is the recommended way to initialize the database (create and populate the database objects)? I'd prefer to put external file for all DDL and DML needs.
I'm still confused on how to put the three parts together.
thanks
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help with his issue? anybody? thanks
 
Marshal
Posts: 5003
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. You don't have to use Oracle for your automated testing, you can use an in memory DB as you suggest. But... this assumes that you are not using any Oracle specific syntax or data types in your schema, in which case you're stuck with Oracle. Although it would be worth checking to see if your Oracle db has an in memory mode that you could use for local testing and CI.

2. Pass. Refer to the DBUnit documentation to see which is suitable for your purposes.

3. My experience with DBUnit has required that the database already be created with the correct schema. Then for your tests you have an xml file that describes the content you want loaded into it.

It's always a good idea to have tests in place that verify the correct integration with the actual database you're going to be using. As these would be Integration Tests you can expect them to be slow and a bit of a pest to setup, i.e. having to make a real Oracle db available. Due to this I would keep the number of tests relatively small, just enough to give you confidence that it's ok. However for your application Unit Tests, of which there would be much more, I would usually swap out the DAO classes with fakes either with a Mocking framework such as Mockito or even just write a test double version that is backed by a Map. That way your Unit Tests are fast and require no external resources.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, for unit tests for all my objects other than DAO objects, I use fakes. the problem is, now I want to test DAO objects, so DBUnit it is. thanks
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic