我正在为 Camunda 工作流程编写测试用例。我正在使用 SpringRunner@RunWith(SpringRunner.class)
并在测试执行所需的测试类中具有以下属性
@Autowired
private ProcessEngine processEngine;
@Rule
@ClassRule
public static ProcessEngineRule rule;
@PostConstruct
void initRule() {
rule = TestCoverageProcessEngineRuleBuilder.create(processEngine).withDetailedCoverageLogging().build();
}
@Mock
ProcessScenario someProcessScenario;
此外,在每个测试中,我都会像这样实例化 ProcessInstance
ProcessRunner.ExecutableRunner.StartingByStarter starter = Scenario.run(someProcessScenario)
.startBy(() -> {
processInstance = rule.getRuntimeService().startProcessInstanceByKey("PROCESS_DEFINITION", properties);
return processInstance;
});
starter.engine(rule.getProcessEngine());
此配置工作正常,我使用 BpmnAwareTests 断言并且所有测试都通过了。我在 pom 中使用的依赖项是
<dependency>
<groupId>org.camunda.bpm.assert</groupId>
<artifactId>camunda-bpm-assert</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-assert-scenario</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-process-test-coverage</artifactId>
<version>0.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm.extension.mockito</groupId>
<artifactId>camunda-bpm-mockito</artifactId>
<scope>test</scope>
<version>4.12.0</version>
</dependency>
由于这个设置为每个测试类实例化了 spring 容器,我想改变几个类来运行 MockitoJUnitRunner 而不是 SpringRunner。所以我把那些改成@RunWith(MockitoJUnitRunner.class)
并像这样初始化所需的属性:
@Rule
public ProcessEngineRule rule = new ProcessEngineRule();
@Mock
ApplicationEventPublisher eventPublisher;
@Mock
ProcessScenario someOtherProcess;
@Mock
SomeClass someclass;
@Before
public void setUp() throws MyCustomiException {
MockitoAnnotations.openMocks(this);
MyDelegate myDelegate = new MyDelegate(someclass);
Mocks.register("myDelegate", myDelegate);
......
}
ProcessInstance 在上面的所有测试用例中都被实例化。这些测试也可以顺利运行并独立通过。但是,当我运行所有测试(一些使用 SpringRunner 和其他使用 MockitoJUnitRunner 运行)时,它们没有通过。SpringRunner 的所有测试都失败了,在 SpringRunner 之后执行的测试也失败了。错误是java.lang.IllegalStateException: No ProcessEngine found to be registered with ProcessEngines!