Spring Test DBunit Warning

后端 未结 4 1813
迷失自我
迷失自我 2021-02-19 03:45

I am using spring-test-dbunit and I get a warning in my Unit tests with this message:

Code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-19 04:08

    To complement the existing answers, I just wanted to add what worked for me in a Spring Boot context, using the Spring Boot configured datasource. Add the following class in your test sources (in a package that will be picked up by autoconfig) :

    @Configuration
    public class DBUnitConfig {
    
        @Autowired
        private DataSource dataSource;
    
        @Bean
        public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
            DatabaseConfigBean bean = new DatabaseConfigBean();
            bean.setDatatypeFactory(new H2DataTypeFactory());
    
            DatabaseDataSourceConnectionFactoryBean dbConnectionFactory = new com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean(dataSource);
            dbConnectionFactory.setDatabaseConfig(bean);
            return dbConnectionFactory;
        }
    }
    

提交回复
热议问题