I am working on creating Integration test cases for my rest controller. I want to use dbunit to test the database layer.
Here is my test class skeleton setup
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= {IntegrationTestApplicationContext.class})
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class })
public class TestServiceControllerIntegrationTest {
private MockMvc mockMvc;
@Test
public void testSearch(){
}
}
Running this code gives me this error
Results :
Tests in error:
initializationError(test.controllers.rest.TestServiceControllerIntegrationTest):
org/dbunit/operation/DatabaseOperation
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
Here's how IntegrationTestApplicationContext.java looks like
@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;
}
}
Guys please help me find the cause and solution of the problem.
Thanks, Fahad Rauf