Java 测试容器&x2B;dbrider:无法清除表X,消息:启用自动提交时无法提交。原因:null
有一个简单的Spring boot应用程序,具有以下集成测试配置:Java 测试容器&x2B;dbrider:无法清除表X,消息:启用自动提交时无法提交。原因:null,java,spring-boot,dbunit,testcontainers,Java,Spring Boot,Dbunit,Testcontainers,有一个简单的Spring boot应用程序,具有以下集成测试配置: @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource(ResourceUtils.CLASSPATH_URL_PREFIX + "application-test.properties") @AutoConfigureMockMvc @DBRider @DBUnit(caseInsensiti
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(ResourceUtils.CLASSPATH_URL_PREFIX + "application-test.properties")
@AutoConfigureMockMvc
@DBRider
@DBUnit(caseInsensitiveStrategy = Orthography.LOWERCASE, qualifiedTableNames = true)
public abstract class AbstractIntegrationTest {
protected static final PostgreSQLContainer<?> POSTGRESQL_CONTAINER; // shared among all test classes
static {
POSTGRESQL_CONTAINER = new PostgreSQLContainer<>("postgres:9.5-alpine");
POSTGRESQL_CONTAINER.start();
}
@Autowired
protected MockMvc mockMvc;
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", POSTGRESQL_CONTAINER::getJdbcUrl);
registry.add("spring.datasource.username", POSTGRESQL_CONTAINER::getUsername);
registry.add("spring.datasource.password", POSTGRESQL_CONTAINER::getPassword);
}
@Test
void contextLoads() {
Assertions.assertThat(mockMvc).isNotNull();
Assertions.assertThat(POSTGRESQL_CONTAINER.isRunning()).isTrue();
}
}
我收到以下警告信息:
WARN com.github.database.rider.core.dataset.DataSetExecutorImpl-无法清除表用户,消息:启用自动提交时无法提交,原因:null
错误的原因是我指定了dbunit应该在之前清除
我不确定我应该怎么做才能摆脱这个警告,有趣的是,桌子被清理了,尽管警告说不是这样
public class UserControllerTest extends AbstractIntegrationTest {
@Test
@DataSet(value = {"/dbunit/users.yml"}, cleanBefore = true)
void getUserTest() throws Exception {
var resultActions = mockMvc.perform(get("/api/users/{id}", 1)
.accept(MediaType.APPLICATION_JSON))
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
// Other tests ommitted.
}