dbunit

【已解决】mysql+unitils用@DataSet,抛NoSuchColumnException

≯℡__Kan透↙ 提交于 2019-11-29 01:24:48
是unitils的一个bug。 使用mysql,用@DataSet注入测试数据时,会抛出org.dbunit.dataset.NoSuchColumnException。 起因是新版本的dbunit(目前是2.4.9)细化了各种数据库的MetadataHandler的处理,为每一种数据库提供了一个MetadataHandler,如MySqlMetadataHandler,Db2MetadataHandler等。而unitils并没有升级(快两年没更新了,还会更新吗?),仍然使用dbunit提供的DefaultMetadataHandler。这个DefaultMetadataHandler并不能很好的处理各个数据库之间的不同,所以会导致兼容问题。 有一种解决方案是将dbunit降级成2.4.2版本,虽然能解决这个问题,但是会引入新的问题。如果在数据XML文件中写入同一个表的两条数据,如: <?xml version='1.0' encoding='UTF-8'?> <dataset> <t_role id="1" name="test1" version="0" /> <t_role id="2" name="test2" version="0" /> </dataset> 则会抛出org.dbunit.database.AmbiguousTableNameException

dbunit经典的NoSuchColumnException解决之道

十年热恋 提交于 2019-11-29 01:24:30
抱怨 dbunit这么多人用,这个项目居然好像没有人在维护了,自动2012年9月release一个版本后,再没有更新了,寒心啊。 dbunit有一个大大的BUG,即会解释不了MySQL表的结构,在使用@DataSet准备数据时,会抛出类似如下的异常: Java代码 Caused by: org.unitils.core.UnitilsException: Error while executing DataSetLoadStrategy at org.unitils.dbunit.datasetloadstrategy.impl.BaseDataSetLoadStrategy.execute(BaseDataSetLoadStrategy.java: 46 ) at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java: 230 ) at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java: 153 ) ... 35 more Caused by: org.dbunit.dataset.NoSuchColumnException: t_upload_file.ID - (Non-uppercase input column: id)

快速JavaEE轻量级框架&公用业务模块 设计&实现 6.1

落爺英雄遲暮 提交于 2019-11-29 01:22:39
使用unitils的dbunit模块进行测试。 真正的去访问数据库,每次测试之前打开一个事务,插入测试数据,业务操作,断言测试数据,回滚。 其中unitils+dbunit实现了除业务操作之外的所有步骤。 dbunit提供了将xml直接转换为数据库数据的功能。 unitils则进一步封装,提供了@DataSet,@ExpectDataset以及事务管理等功能,可以通过annotation的方式将数据文件导入数据库,也可以通过xml去断言数据,并且支持自动回滚,超级方便。 这里在使用 unitils整合dbunit的时候碰到了两个问题,记录一下。 关于问题,请分别查看下面两篇文章: unitils使用@DataSet插入测试数据,测试结束后不能回滚 mysql+unitils用@DataSet,抛NoSuchColumnException 最后,贴上一段标准DAO测试的代码: @DataSet public final class RoleDaoTest extends IntegrateBaseTest { @SpringBeanByType private RoleDao roleDao; @Test @ExpectedDataSet public void save() { Role role = new Role(); role.setName("Test Role");

Is there a dbunit-like framework that doesn't suck for java/scala?

家住魔仙堡 提交于 2019-11-28 14:52:46
问题 I was thinking of making a new, light-weight database population framework. I absolutely hate dbunit. Before I do, I want to know if someone already did it. Things i dislike about dbunit: 1) The simplest format to write and get started is deprecated. They want you to use formats that are bloated. Some even require xml schemas. Yeah, whatever. 2) They populate rows not in the order you write them, but in the order tables are defined in the xml file. This is really bad because you can't order

【已解决】unitils使用@DataSet插入测试数据,测试结束后不能回滚

久未见 提交于 2019-11-27 20:49:40
使用@DataSet的时候,unitils使用的事务管理器必须在spring的配置文件中定义。 <bean id="dataSource" class="org.unitils.database.UnitilsDataSourceFactoryBean" /> 否则@DataSet会使用unitils的事务管理,而在测试方法里操作业务DAO会使用spring的事务管理,造成的后果是操作DAO生成的数据可以回滚,但是@DataSet导入的数据不能回滚。 来源: oschina 链接: https://my.oschina.net/u/719192/blog/173642

How to revert the database back to the initial state using dbUnit?

冷暖自知 提交于 2019-11-27 18:12:28
问题 I am new to automated testing and dbUnit. So I would appreciate your advice. I am going to create a test suite, that will run the following way: create an in-memory H2 database run DDL scripts to create tables run dbUnit to insert initial data (let's call it STATE0 ) that will be used by all tests. run tests Till there it looks nice for me, but what I don't understand, is how do I revert the database to the STATE0 after a test run and changed the data? Can I do it with dbUnit? Or with

【让开发自动化】Unitils与DBUnit 兼容性问题

我与影子孤独终老i 提交于 2019-11-27 17:31:52
由于系统里用到了POI-3.5.FINAL用于Excel的处理,而unitils配套的DBUnit才2.2版本,与POI-3.5版本冲突,需要升级DBUnit的版本。目测最新版为2.4.9,与POI-3.5正好配套,一运行,出现如下异常: org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method public void com.litt.cidp.system.service.OperatorServiceTest.test_load() at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:156) at org.unitils.dbunit.DbUnitModule$DbUnitListener.beforeTestSetUp(DbUnitModule.java:557) at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273) at org.unitils.UnitilsJUnit4TestClassRunner

Is there any way for DBUnit to automatically create tables?

删除回忆录丶 提交于 2019-11-27 14:36:50
I just realized that DBUnit doesn't create tables by itself (see How do I test with DBUnit with plain JDBC and HSQLDB without facing a NoSuchTableException? ). Is there any way for DBUnit to automatically create tables from a dataset or dtd? EDIT: For simple testing of an in-memory database like HSQLDB, a crude approach can be used to automatically create tables: private void createHsqldbTables(IDataSet dataSet, Connection connection) throws DataSetException, SQLException { String[] tableNames = dataSet.getTableNames(); String sql = ""; for (String tableName : tableNames) { ITable table =

org.dbunit.dataset.NoSuchTableException: Did not find table 'xxx' in schema 'null'

烂漫一生 提交于 2019-11-26 23:18:05
问题 I know there have been discussions wrt to dbunit here. I have read most of them but I cant seem to find a solution to my problem. I have set up hibernate and spring. I am doing TDD so I had to wire up a proper DAO testing framework before writing code. Dbunit came to mind and I got to setting it up. Here is ma testdataset.xml <?xml version='1.0' encoding='UTF-8'?> <dataset> <table name="status"> <column>statusId</column> <column>status</column> <row> <value>0</value> <value>Available</value>

How to load DBUnit test data once per case with Spring Test

China☆狼群 提交于 2019-11-26 21:36:42
问题 Spring Test helpfully rolls back any changes made to the database within a test method. This means that it is not necessary to take the time to delete/reload the test data before each test method. But if you use the @BeforeClass Junit annotation, then that forces the data loader to be static. A question that is explored here: Why must jUnit's fixtureSetup be static? If the data initialization method is static, so must the data connection methods and the data source..and on and on...forcing