0

我正在为我的休息控制器创建集成测试用例。我想使用 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;
    }
}

请各位大侠帮我找出问题的原因和解决方法。

谢谢,法赫德·劳夫

4

1 回答 1

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

这看起来像一个类路径错误。我怀疑整个错误是ClassNotFound:org/dbunit/operation/DatabaseOperation

你能检查以确保 dbunit 及其所有依赖项都在类路径上吗?DBUnit 有很多依赖项。

于 2013-01-05T02:02:48.260 回答