如果我使用以下设置运行dbunit并在集成测试中通过HTTP请求数据,我没有得到任何数据,因为数据库是空的.DBUnit将数据写入数据库,但是当我通过HTTP请求数据时它是空的.
这是我的设置:Spring Boot 1.1.7 with spring-boot-starter-web(不包括tomcat),spring-boot-starter-jetty,spring-boot-starter-data-jpa,spring-boot-starter-test,liquibase -core,dbunit 2.5.0,spring-test-dbunit 1.1.0
主要应用类别:
@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
@EnableTransactionManagement
@EnableJpaRepositories
Run Code Online (Sandbox Code Playgroud)
测试配置(application-test.yaml):
logging.level.org.springframework: DEBUG
logging.level.org.dbunit: DEBUG
spring.jpa.properties.hibernate.hbm2ddl.auto: update
spring.jpa.database: h2
spring.jpa.show-sql: true
// setting these properties to access the database via h2 console
spring.datasource.url: jdbc:h2:tcp://localhost/mem:my_db;DB_CLOSE_DELAY=-1;MVCC=true;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username: sa
spring.datasource.password: sa
spring.datasource.driverClassName: org.h2.Driver
spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
liquibase.change-log: classpath:/db/changelog/db-master.xml
Run Code Online (Sandbox Code Playgroud)
整合测试:
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = HDImageService.class)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class })
@WebAppConfiguration
@IntegrationTest("server.port:0")
@DatabaseSetup("/database_seed.xml")
@DatabaseTearDown(value = "/database_tear_down.xml", type = DatabaseOperation.DELETE_ALL)
// test
@Test
public void get_works() throws Exception {
// given …Run Code Online (Sandbox Code Playgroud)