Testing of ExecutionListeners with JUnit & Mockito

Hi all,

I tried to use various integration and unit testing options for our spring-boot based processes. I have first checked the resources Testing examples, Process testing and Assert API.

Now we can roughly test process paths and delegate class execution unit test. However, mocking of the attributes of the classes derived from ExecutionListener does not really work, which ends up with a NPE at some point in the execution.

Based on the following code snippets and BPMN views can anyone tell me, what could be the problem? or is it the camunda internal class instantiation that differ between Listeners and Delegates?

Class under test:

public class ActivationLinkListener implements ExecutionListener {

  private static final Logger LOGGER = LoggerFactory.getLogger(ActivationLinkListener.class);

  private ProcessAVariables processAVars;

  public void notify(DelegateExecution delegateExecution) {
    Integer resendCount = processAVars.getResendCounter();
    if (smsResend == null){
      smsResend = 0;
    LOGGER.info("BV Registration ActivationLinkListener called. Retry : " + resendCount++);

Test Code:

@Deployment(resources = "bpmn/ProcessA.bpmn")
public class ActivationLinkListenerTest extends AbstractProcessEngineRuleTest {

  public static ProcessEngineRule engineRule = TestCoverageProcessEngineRuleBuilder.create().build();

  private ProcessAVariables processAVars;

  private ActivationLinkListener activationLinkListener;

  public void setUp() {
    // Initialize mocks created above
    Mocks.register("activationLinkListener", activationLinkListener);

  public void teardown() {
    // calculate coverage for all tests

  public void startProcessAtSendActivationLinkDelegate() {

    // Intermediate given & received

    // Process run at the right task

    // Then ...

  private void runProcessAtActivationLinkListener() {
    VariableMap variables = Variables.createVariables()
      .putValue(ProcessAConstants.RESEND_COUNT, 1)
      .putValue(ProcessAConstants.MAX_RESEND_LIMIT, 3);


ProcessA.bpmn (7.5 KB)

Thanks a lot in advance.


Hi @tunch,

maybe you’re missing the initialization of the engine:

  public void setup() {

Hope this helps, Ingo

Thanks @Ingo_Richtsmeier but it did not help. I believe the process engine is initialized correctly. It starts and arrives to the listener class during testing as expected. I also see that in the test thread the mocks (ProcessAVars) are set and injected correctly to the activationLinkListener.

The mocked processAVars is still simply null when the process arrives to the context of activationLinkListener. Either Mockito cannot mock it due to some Camunda internal mechanisms, or Camunda forces a new instantiation of this class during process run.
It would be really good to understand why.