View source | Discuss this page | Page history | Printable version   

ERP 2.50:Automated Testing/DbUnit



DbUnit is a testing tool that allows to:

It uses Datasets (a collection of tables) to manipulate tabular data.

And it has a set of Database operations that can be performed on the database.

So a collection of tables and the values of their records are defined, and before or after the execution of a test an operation is executed to insert, update or delete those values from the database.

This way it's much easier to handle the database dependencies of a test, because we will now at every moment what the state of the database is.

Helper classes

We have coded some helper classes to make it easier the loading of datasets into Openbravo database using DbUnit.


Some test cases will need to disable the execution of table triggers when the dataset is inserted on the database, in order to properly test a specific feature.

The class com.openbravo.test.integration.dbunit.Triggers helps to disable and enable the triggers of a list of tables.

Note: Please avoid disabling triggers as much as possible because if two tests disable and enable the triggers of the same table, it won't be possible to execute them in parallel.


A specific DataTypeFactory has to be set to the connection of every database provider in order to use all the features available.

So, in Openbravo a different connection is required to insert datasets to Oracle and to Postgresql. The class com.openbravo.test.integration.dbunit.Connections returns the proper DbUnit connection for each of them.


We use multiple small FlatXMLDataSets to define the dependencies that will be loaded to database before the execution of tests.

With the class com.openbravo.test.integration.dbunit.FlatXmlDataSets it is possible to export a XML file with the dataset corresponding to a SQL query.


Multiple small FlatXMLDataSets are composited into a single dataset that will be loaded into database before the execution of tests.

The class com.openbravo.test.integration.dbunit.CompositeDataSets makes it easier to make the composite dataset from a list of FlatXMLDataSet files.


In order insert unique records from the same datasets, we set place holder objects in the records and change them from unique identifiers every time that a test is executed.

The function replaceWithUUIDs of the class com.openbravo.test.integration.dbunit.ReplacementDataSets replaces all placeholder objects with UUIDs.

Retrieved from ""

This page has been accessed 8,142 times. This page was last modified on 3 April 2012, at 11:00. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.