I am writing test cases for Camunda workflows. I am using SpringRunner @RunWith(SpringRunner.class)
and have the following properties in Test class required for the test execution
@Autowired
private ProcessEngine processEngine;
@Rule
@ClassRule
public static ProcessEngineRule rule;
@PostConstruct
void initRule() {
rule = TestCoverageProcessEngineRuleBuilder.create(processEngine).withDetailedCoverageLogging().build();
}
@Mock
ProcessScenario someProcessScenario;
Further, in each test I instantiate the ProcessInstance like this
ProcessRunner.ExecutableRunner.StartingByStarter starter = Scenario.run(someProcessScenario)
.startBy(() -> {
processInstance = rule.getRuntimeService().startProcessInstanceByKey("PROCESS_DEFINITION", properties);
return processInstance;
});
starter.engine(rule.getProcessEngine());
This configuration works fine and I assert using BpmnAwareTests and all tests pass. The dependencies that I have used in the pom are
<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>
Since this setup instantiates the spring container for every test class, I thought to change few classes to run with MockitoJUnitRunner than SpringRunner.
So I changed those to @RunWith(MockitoJUnitRunner.class)
and initialize the required properties like this:
@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 is instantiated in all test cases as above. These tests also run smooth and pass independently. However, when I run all tests (some which run with SpringRunner and others with MockitoJUnitRunner) they do not pass. All tests with SpringRunner fail and the ones that execute after SpringRunner also fail. The error is java.lang.IllegalStateException: No ProcessEngine found to be registered with ProcessEngines!