Magazine
 
DbTesting with DbUnit

DbUnit :

DbUnit is an open source Framework created by Manuel Laflamme. This is a powerful tool for simplifying Unit Testing of the database operations. It extends the popular JUnit test framework that puts the database into known state while the test executes. This strategy helps to avoid the problem that can occur when one test corrupts the database and causes subsequent test to fail. DbUnit provides a very simple XML based mechanism for loading the test data, in the form of data set in XML file, before a test runs. Moreover the database can be placed back into its pre-test state at the completion of the test.

Advantages of DbUnit :

The reasons to use this testing tool can be summarized as follows :

1 A framework which simplifies operations for each stage in the life cycle of individual database tests.

 

2 It provides a very simple XML based mechanism for loading test data.

3 It provides equally a simple mechanism to export existing
test data into the XML format for subsequent use.

4 It can work with very large datasets.

5 It can help verify your data matches an expected set of values.

6 It provides methods for comparing data between flat files, queries and database tables.


Setting up the environment :

To run the example of DbUnit in
Eclipse, we need jar files of DbUnit, JUnit and Jakarta Commons IO. DbUnit is available from DbUnit
web site, http://www.dbunit.org. JUnit is available from http:// www.junit.org. commons-io-1.3.2.jar can be found from http://mirrors.kahuki.com/ apache/commons/io/binaries
/commons-io- 1.3.2-bin.zip. Now these jar files are required to be added in the referenced library of your testing directory.



Sept 2007 | Java Jazz Up | 40
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   Download PDF