(Quick Reference)

7 Testing Guide - Reference Documentation

Authors: Martin Schimak

Version: 0.5.0

7 Testing Guide

During the integration test phase of Grails (any environment), two configuration values are set by the plugin: the camunda job executor is *by default turned off* and service mocking is made available.

Beware: you can explicitely turn on/off the job executor in your environment by configuration. In this case the plugin will not interfere with your explicit choice!

In essence this behaviour makes sure that you can perform your tests

  • in a single-threaded manner, fully controlled by your test code, and without having the job executor interfering from background threads.
  • with the possibility to mock your service calls from within the process

7.1 Drive the process instances

For testing purposes, you can (and must!) explicitely "drive" your process whenever it arrives at a "wait state". Please review the discussion about transactions in processes to learn more about that. Such a wait state is always reached for e.g. user tasks, but with the job executor turned off in particular also for service tasks marked to be continued asynchronously:

<serviceTask id="myServiceTask" … camunda:async="true"></serviceTask>

In such a case you must now mimic the work of the background job executor and explicitely tell the process to "move on" with execution, e.g. by writing:

def job = managementService.createJobQuery().processInstanceId(pid).singleResult()
managementService.executeJob(job.id)

7.2 Mock the service calls

You can call services from within your process via JUEL expressions, like e.g.

<serviceTask id="myServiceTask" camunda:expression="#{sampleTestProcessService.serviceMethod(execution)}" … >
…
</serviceTask>

For your tests, instead of calling your actual service 'sampleTestProcessService' you can call a mock, like e.g.

def sampleTestProcessService = Mock(SampleService)
org.camunda.bpm.engine.test.mock.Mocks.register("sampleService", sampleTestProcessService)

This will make sure that the juel identifier 'sampleService' will be resolved to the mock instance, provided you use the MockExpressionManager for resolving your JUEL expression identifiers - which is what the plugin will make sure for Grails' integration test phase.

7.3 Auto reload and redeploy your bpmn process definitions

You can automatically reload and redeploy '.bpmn' process definitions placed beneath 'grails-app/processes'. When changing the process definition while you are running your application with 'run-app', it will be redeployed to the process engine.

Also check the possibility to turn this feature on/off explicitely by configuration.