の列を持つ MySQL のテーブルに対して、dbUnit を使用して統合テストを作成しようとしていますautoincrement
。統合テストは次のようになります。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={
JdbcRepositoryConfiguration.class,
DbUnitConnectionConfiguration.class
})
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
DbUnitTestExecutionListener.class
})
@DirtiesContext(classMode=ClassMode.AFTER_CLASS)
@DbUnitConfiguration(databaseConnection="dbUnitConnection")
public class IntegrationTest {
@Autowired private JdbcRepositoryConfiguration configuration;
private Loader loader;
@Before
public void setup() throws JSchException {
loader = new Loader(configuration.jdbcTemplate());
}
@Test
@DatabaseSetup("classpath:dataset.xml")
public void loads() throws Exception {
assertThat(loader.load(), contains("something"));
}
}
列のないテーブルに対して同じ統合テスト構造がincrement
あり、テストは正常に機能します。次のdataset.xml
ようになります。
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<sometable
id="1"
regexp="something"
descr="descr"
/>
</dataset>
デバッグ データをセットアップするために実行されるアクションは、すべてを削除して挿入を実行することであることがわかります。具体的には次のとおりです。
何らかのテーブル (id、regexp、descr) 値 (?、?、?) に挿入します。
私が得るエラーは次のとおりです。
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'regexp, descr) values (1, 'something', 'descr')' at line 1
完全を期すために、DbUnitConfiguration.class
には次の Spring Bean 設定があります。
@Bean
public IDatabaseConnection dbUnitConnection() throws SQLException, DatabaseUnitException, JSchException {
Connection dbConn = configuration.jdbcTemplate().getDataSource().getConnection();
IDatabaseConnection connection = new DatabaseConnection(dbConn) {
@Override
public void close() throws SQLException {}
};
DatabaseConfig dbConfig = connection.getConfig();
dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
return connection;
}