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的測試前的功能?