tags:

views:

790

answers:

2

In the setup method to a JUnit test case I'm working on I need it to run a sql script on my database before each test case, and then a rollback afterwards.

I have tried using a tokenizer, which added each SQL command to a batch and then executing them. But I can't get working. So my question is if there is some standard method in JUnit to perform this action?

A: 

You can try DbUnit

Aaron Digulla
A: 

It's not the task of JUnit to test SQL statements.

You should create a Mocker (EasyMock e.g.) and isolate the connection. So the mocker can imitate the sql connection and its results. With this mocking object, you can check, if your sql connector class called the right statements.

If you want to test the SQL statement, its results and so on, you should use DBUnit, as Aaron said.

furtelwart