Ant Integration
Installation
The steps required to add the DbUnit task to your system are:
- Add the DbUnit jar to Ant’s classpath. You may alternatively use the 'classpath' attribute of
<taskdef>. - Add a
<taskdef>element to your build script as follows:
<taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask"/>- Use the task in the rest of the buildfile.
Usage
Executes either a single transaction, or a group of transactions, under the DbUnit database testing framework.
Parameters
| Attribute | Description | Required |
|---|---|---|
| driver | Class name of the jdbc driver. Must be available on the classpath (either system classpath or nested classpath) | Yes |
| url | Database connection url | Yes |
| userid | Database username | Yes |
| password | Database password | Yes |
| schema | Database schema | No |
| classpath | Classpath used to load driver. | No (use system classpath) |
| useQualifiedTableNames | Set the qualified table names feature. Defaults to false. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| supportBatchStatement | Set the batched statement feature. Defaults to false. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| datatypeWarning | Set the data type warning feature. Defaults to true. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| escapePattern | Set the escape pattern property. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| datatypeFactory | Set the datatype factory property. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| skipOracleRecycleBinTables | Set the skipOracleRecycleBinTables feature. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| batchSize | Set the batchSize property. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| fetchSize | Set the fetchSize property. @deprecated since 2.4. Use nested dbconfig element instead. | No |
| allowEmptyFields | Set the allowEmptyFields feature. @deprecated since 2.4. Use nested dbconfig element instead. | No |
Parameters Specified as Nested Elements
classpath
DbUnit’s classpath attribute is a PATH like structure and can also be set via a nested classpath element. It is used to load the JDBC classes.
dbconfig
DbUnit’s configuration parameters to set any of the properties for the database connection. It supports all properties and features from the DatabaseConfig java class, having the last path component of the property/feature URL as name. A more detailed example is shown at dbconfig-example.
The nested <property> element and the nested <feature> element looks as follows:
| Attribute | Description | Required |
|---|---|---|
| name | The name of the property/feature which must be the last path component of the property/feature URL (see properties for more). Example: for the property "http://www.dbunit.org/properties/tableType" the name is "tableType". | Yes |
| value | The value of the property/feature as string. Since feature are boolean values the string can take one of the values "true" or "false". | Yes |
operation
Use nested <query> elements to export data according to a sql statement.
| Attribute | Description | Required |
|---|---|---|
| type | Type of Database operation to perform. Supported types are UPDATE, INSERT, DELETE, DELETE_ALL, REFRESH, CLEAN_INSERT, MSSQL_INSERT, MSSQL_REFRESH, MSSQL_CLEAN_INSERT. | Yes |
| src | The source file upon which the operation is to be performed | Must specify either src or fileset |
| fileset | The source files upon which the operation is to be performed. The source files make up a composite dataset. | Must specify either src or fileset |
| format | Format type of supplied source file(s). Possible values are "flat", "xml", "csv", "dtd", "xls", "yml". Defaults to "flat" | No |
| combine | Boolean indicating if tables in a composite dataset having the same name should be merged into one table. Possible values are "true" or "false". Defaults to "false". | No |
| transaction | Boolean indicating if this operation should be wrapped in a transaction, ensuring that the entire operation completes or is rolled back. This may also dramatically improve performance of large operations. Possible values are "true" or "false". Defaults to "false". | No |
| ordered | If set to "true" the tables of the exported dataset are ordered using a database key. Therefore dbunit uses the FilteredDataSet combined with the DatabaseSequenceFilter. Defaults to "false" | No |
| nullToken | A String used to replace all occurrences of this String in a dataset with <null>. A common value for this is "[NULL]". Defaults to null which means that no replacement occurs. |
No |
export
Use nested <export> operation elements to export the database to the supplied filename.
The default operation is to export the entire database to the destination filename with the supplied dataset type.
You can specify individual tables or queries to export by nesting them under the <export> step.
| Attribute | Description | Required |
|---|---|---|
| dest | The xml destination filename | Yes |
| format | Format type of supplied destination file. Possible values are "flat", "xml" or "dtd". Defaults to "flat" | No |
| doctype | If set and format is "flat", add DOCTYPE declaration referencing specified DTD to exported dataset. The DTD path can be absolute or relative. | No |
| ordered | If set to "true" the tables of the exported dataset are ordered using a database key. Therefore dbunit uses the FilteredDataSet combined with the DatabaseSequenceFilter. Defaults to "false" | No |
| encoding | Desired encoding for XML-Output. Possible values are valid XML-Endings like "UTF-8" or "ISO-8859-1". Defaults to "UTF-8" | No |

