我想为Flowable写一些单元测试,但是不同的方法可能会有数据冲突。如何清除两种测试方法之间的测试数据?
我尝试了注释@DirtiesContext
,但没有用。
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
@Import(TestConfig.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class FlowableTest {
@Autowired
private ProcessEngine processEngine;
@Test
public void test() {
IdentityService identityService = processEngine.getIdentityService();
Group defaultGroup = identityService.newGroup("default");
defaultGroup.setName("233333");
identityService.saveGroup(defaultGroup);
}
@Test
public void test2() {
IdentityService identityService = processEngine.getIdentityService();
Group defaultGroup = identityService.newGroup("default");
defaultGroup.setName("233333");
identityService.saveGroup(defaultGroup);
// do some thing
}
}
这是错误信息。
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Unique index or primary key violation: "PUBLIC.PRIMARY_KEY_6B ON PUBLIC.ACT_ID_GROUP(ID_) VALUES 1"; SQL statement:
insert into ACT_ID_GROUP (ID_, REV_, NAME_, TYPE_)
values (
?,
1,
?,
?
) [23505-199]
然后我想在每个方法之前手动创建表,我在“flowable-engine-6.4.1.jar”中找到了“flowable.h2.create.history.sql”和“flowable.h2.create.engine.sql” ,但是当我重新运行这些单元测试时,我发现缺少很多列。
有什么简单的方法可以清除所有测试数据吗?