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).
posted 7 years ago
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.