Java 如何清除两个单元测试方法之间的所有测试数据?

Java 如何清除两个单元测试方法之间的所有测试数据?,java,spring-boot,flowable,Java,Spring Boot,Flowable,我想为Flowable编写一些单元测试,但是不同的方法可能会有数据冲突。我应该如何清除两种测试方法之间的测试数据 我尝试了注释@DirtiesContext,但没有成功 @RunWith(SpringRunner.class) @春靴测试 @AutoConfigureMockMvc @ActiveProfiles(“测试”) @导入(TestConfig.class) @DirtiesContext(classMode=DirtiesContext.classMode.AFTER\u每个\u测试

我想为Flowable编写一些单元测试,但是不同的方法可能会有数据冲突。我应该如何清除两种测试方法之间的测试数据

我尝试了注释
@DirtiesContext
,但没有成功

@RunWith(SpringRunner.class)
@春靴测试
@AutoConfigureMockMvc
@ActiveProfiles(“测试”)
@导入(TestConfig.class)
@DirtiesContext(classMode=DirtiesContext.classMode.AFTER\u每个\u测试\u方法)
公共级流动性试验{
@自动连线
私有进程引擎进程引擎;
@试验
公开无效测试(){
IdentityService IdentityService=processEngine.getIdentityService();
Group defaultGroup=identityService.newGroup(“默认”);
defaultGroup.setName(“233333”);
identityService.saveGroup(defaultGroup);
}
@试验
公共无效测试2(){
IdentityService IdentityService=processEngine.getIdentityService();
Group defaultGroup=identityService.newGroup(“默认”);
defaultGroup.setName(“233333”);
identityService.saveGroup(defaultGroup);
//做点什么
}
}
这是错误消息

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.h2.create.history.sql”和“flowable.h2.create.engine.sql” 在“flowable-engine-6.4.1.jar”中,但是当我重新运行这些单元测试时,我发现缺少很多列


有什么简单的方法可以清除所有测试数据吗?

在可流动代码库中执行测试的方法和我在其他项目中执行测试的方法是手动删除每个测试中的数据。这背后的原因是您知道在测试中创建了哪些数据


例如,在您的特定测试中,您可以删除
@After
方法中的所有组。

在可流动代码库中执行测试的方式和我在其他项目中执行测试的方式是手动删除每个测试中的数据。这背后的原因是您知道在测试中创建了哪些数据

例如,在特定测试中,您可以删除
@After
方法中的所有组