I want to write some unit tests for Flowable, but different methods may have data conflicts. What should I do to clear the test data between two test methods?
I tried the annotation @DirtiesContext
but it didn't work.
@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
}
}
This is the error message.
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]
And then I want to create tables manually before each method, I found the "flowable.h2.create.history.sql" and "flowable.h2.create.engine.sql" in "flowable-engine-6.4.1.jar" ,but when I rerun these unit tests, I found there are lots of columns missing.
Is there any easy way to clear all test data?