Camunda BPMN testing with Mockito

Published On: 2019/08/12

Unit testing of a BPMN is not simple as that of a java class. Camunda mockito extension has provided a simple implementation to create unit tests for BPMN. In this article we will walk through a sample test case of customer activation BPMN in the cloudmessage platform.

Maven Configuration


BPMN Diagram

In the customer activation process, systems sends a message to the customer with activation link and then wait for the customer action. When the customer clicks on the link a message will be sent back to the system to resume the process.

Testcase Implementation

The full implementation of this testcase can be viewed here

First step is to create a process engine.

   public final ProcessEngineRule processEngineRule = new ProcessEngineRule(testAwareProcessEngineConfiguration().buildProcessEngine());
As this BPMN has message send and recieve tasks , we need to create two constants for message name and recieve task id.
   private static final String MESSAGE_ACTIVATION_RESULT = "Message_Activation_Result";
   private static final String RECIEVE_ACTIVITY="process_activation_result";
In the test method call the autoMock for the bpmn process which registers mocks for TaskListner, ExecutinListner and JavaDelegate.
Asserts that all the necessary mocks are available.
Configure the deployment with a mock to the recieve message activity.
Verify the mocks for the first to activities using the verify methods of DelegateExpressions.
   verifyExecutionListenerMock("startActivation").executed(); // For Listeners
   verifyJavaDelegateMock("sendActivationRequest").executed(); // For Delegates
As the 3rd stage of the BPMN is message receieve activity, automate it by correlateMessage with message name.


In this article, the testing of a BPMN process using camunda and mockito is covered with a simple project setup . The source code of this project is available in the cloudmessage stream Github repository.

comments powered by Disqus