• 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
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Stubbing a database for unit testing

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking for some kind of library from which I can provide stubs for SQL calls (for unit testing). Kind of like a dummy JDBC driver (a similar idea to JDBCProxy, but better).

It would work in a similar manner to this:

String connectionString = "jdbc:stub:<stub_definition_file>";
Connection connection = DriverManager.getConnection(connectionString, "username", "password");

The stub connection could then be used to create statements, which when executed return whatever data we define in the <stub_definition_file>.


I have a couple of questions:
1) Are there any (mature) existing libraries which do this already?
2) Is this is a good approach to the problem of testing code that accesses a database? (It means we can run unit tests without the dependency of a test database).
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on what you are unit testing.

If I wanted to Unit test the actual SQL (does the SQL do what I think it should) I would use DBUnit to put the database in a known state and make sure I got back the data I wanted.

If I wanted to test some DAOs and make sure the correct SQL was going to be passed to JDBC calls and the resources properly closed I would use Mockrunner - specifically the BasicJDBCTestCaseAdapter.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic