mip
mip

Reputation: 2026

Database base unit testing strategy: truncating tables between unit tests & test data

I'm attempting to use JUnit to test some database code. I'm pretty new to this so please bear with me.

I have a local test database which consists of four tables. Two of these tables are populated with data and the other two are empty before the program executes.

The program basically performs some queries on the two tables which are populated, processes the results then writes those results to the two tables which are empty when the program is executed. There are a number of methods which read and write to the db. I would like to test these.

What I would like is for the tearDown() method to truncate the tables which are empty when the program executes so that they are ready for the next test. What is the best way of achieving this?

Also, the tables which contain the data will probably be created by running SQL script each time a developer sets up a test environment. Is there a better way of doing this? Could it be automated? There will be quite a lot of data so I don't really fancy manually creating XML datasets for each table.

I'm using an Oracle database.

Many thanks for any advice/suggestions you can offer.

Upvotes: 1

Views: 869

Answers (1)

Kurt Du Bois
Kurt Du Bois

Reputation: 7665

Try using the DBUnit framework in your tests. This is an extension to JUnit and provides the functionality you need. Setting it up can be a bit hard, but once set up it works like a charm.

Upvotes: 2

Related Questions