0
我在MS SQL Server中有一个用户定义的函数,它从Java代码调用,在H2数据库中运行集成测试时显示为未定义。你可以在the previous question找到我的代码。DbUnit - JdbcSQLException:函数“*”未找到
测试代码:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {H2Config.class})
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
@TransactionConfiguration(defaultRollback = true)
public class TableDaoTest {
@Autowired
private TableDao tableDao;
@Test
@DatabaseSetup("/datasets/import.xml")
public void testMethod01() {
tableDao.getRecordsByGroup();
...
数据库模式是由Hibernate来自动生成。正如你可以看到测试数据由DbUnit使用xml数据集填充。并且此测试失败,因为我的函数存在于MS SQL服务器数据库中是H2数据库中未定义的。
应用程序日志:
Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
...
Caused by: org.h2.jdbc.JdbcSQLException: Function "SAFE_MOD" not found; SQL statement:
select table10_.id, table10_.value, ... from Table1 table10_ where table10_.group1=dbo.safe_mod(?, ?);
...
如何导入/创建DbUnit的测试前的功能?