Question

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

Was it helpful?

Solution

initializationError(ua.com.stormlabs.geotagger.web.controllers.rest.LocationServiceControllerIntegrationTest): 
org/dbunit/operation/DatabaseOperation

This looks like a classpath error. I suspect the whole error is ClassNotFound:org/dbunit/operation/DatabaseOperation

Can you check to make sure that dbunit and all its dependencies are on the classpath? DBUnit has quite a number of dependencies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top