我正在为我的休息控制器创建集成测试用例。我想使用 dbunit 来测试数据库层。
这是我的测试类骨架设置
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= {IntegrationTestApplicationContext.class})
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class })
public class TestServiceControllerIntegrationTest {
private MockMvc mockMvc;
@Test
public void testSearch(){
}
}
运行此代码给了我这个错误
Results :
Tests in error:
initializationError(test.controllers.rest.TestServiceControllerIntegrationTest):
org/dbunit/operation/DatabaseOperation
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
下面是 IntegrationTestApplicationContext.java 的样子
@Configuration
@PropertySource("classpath:application.properties")
public class IntegrationTestApplicationContext {
@Resource
private Environment environment;
@Bean
public DataSource dataSource() {
BoneCPDataSource dataSource = new BoneCPDataSource();
dataSource.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName"));
dataSource.setJdbcUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
return dataSource;
}
}
请各位大侠帮我找出问题的原因和解决方法。
谢谢,法赫德·劳夫