How to Mock Camunda Expression


I need to create a unit test to a JavaDelegate that uses an Expression from org.camunda.bpm.engine.delegate.Expression. However, I was not able to Mock the Expression. I am using Mockito and it is an integration test.

I am able to mock the DelegateExecution:

private DelegateExecution execution;

Nevertheless, to Expression this is not working.

My Class is as follow:

public class EngineRuleDelegates implements JavaDelegate {

private EngineRulesConnector engineRulesConnector;

private ObjectMapper mapper;

private EngineProperties engineProperties;

private Expression step;

public void execute(DelegateExecution execution) throws Exception {

String stepValue = (String) step.getValue(execution);

Any ideas of how to mock the Expression would be helpful.

Hi @Heloisa_Carbone,

depending on your JUnit setup, you can use Mocks.register("beanName", object instance) to create the expression result manually.

To do this, you have to add the org.camunda.bpm.engine.test.mock.MockExpressionManager as expressionManager in your test engine.

Have a look at this test class
and at this configuration:

Hope this helps, Ingo

1 Like