Unitils when integrating Dbunit, if the database is MySQL, some of the following will appear:
Org.unitils.core.UnitilsException:Error inserting test data from DbUnit DataSet for method ...
Org.dbunit.dataset.NoSuchColumnException ...
The reasons for the above two errors are: Unitils default is to use the "Defaultmetadatahandler.java" class to load the database information, so that the database schema value is not available, The implementation code in Defaultmetadatahandler.java is as follows:
Boolean areEqual = areequalignorenull (catalog, CatalogName, casesensitive) && areequalignorenull ( Schema, SchemaName, casesensitive) && areequalignorenull (table, TableName, casesensitive) && areequalignorenull (column, ColumnName, casesensitive);
This time the schemaname is empty, but the schema is passed in to have value, thus error!
Solutions Two types:
1, change the source code, remove the catalog and schema comparison
2, write an extension class, to inherit Dbunitmodule, the code is as follows:
Import Org.dbunit.database.databaseconfig;import Org.dbunit.ext.mysql.mysqldatatypefactory;import Org.dbunit.ext.mysql.mysqlmetadatahandler;import Org.unitils.dbunit.dbunitmodule;import Org.unitils.dbunit.util.dbunitdatabaseconnection;public class Mysqldbunitmodule extends Dbunitmodule {@Override Pub Lic dbunitdatabaseconnection getdbunitdatabaseconnection (final String schemaName) {Dbunitdatabaseconne ction result = Dbunitdatabaseconnections. Get (SchemaName); if (null! = result) {return result; } result = Super.getdbunitdatabaseconnection (schemaName); Result.getconfig (). SetProperty (Databaseconfig.property_datatype_factory, New MYSQLDATATYPEF Actory ()); Result.getconfig (). SetProperty (Databaseconfig.property_metadata_handler, New Mysqlmetadatah Andler ()); return result; }}
Then modify the Unitils-default.properties file under the Unitils-core jar package,
Unitils.module.dbunit.classname=org.unitils.dbunit.dbunitmodule changed to the following:
Unitils.module.dbunit.classname=org.unitils.dbunit.mysqldbunitmodule
If you use your own defined profile unitils.properties, you only need to modify the custom profile so that you do not need to modify the unitils-default.properties in the jar
Of course, the premise of these problems is that the database being used is the case of MySQL, and the solution ~
Reprint: http://www.cnblogs.com/candle806/p/3807590.html
Unitils Integrated Dbunit problem-solutions