jUnit and Delegate testing with Camunda 7.9.0

Hello everyone,

I try to create a test case with jUnit the following setup:

public class MyClass implements JavaDelegate{

@Override
public void execute(DelegateExecution execution) throws Exception {
  .. do something here with execution...
  }

}

Test class:

public class MyClassTest(

... initialize Camunda process with current model
... initialize execution class

MyClass mClsTest;
execution.insertDataHere();

mClsTest.execute(execution);

assert(check for results here);

}

Somehow I got stuck here, as I have seen so far from the test cases here and on github,
the execution class is checked for NULL. (see DelegateExecutionContextTest.java for example.)
I can initialize the SimpleTestCase with the testProcess.bpmn but still the
execution class is NULL. Basically I am missing how to initialize the test case to be able to feed in data.

Could someone point me to the right direction? Any help would be greatly appreciated.

Greetings
Peter

Hi Peter,

Maybe the Camunda BPM Mockito extension can help you achieve your goal. See in particular this section: https://github.com/camunda/camunda-bpm-mockito#delegatetaskexecutionfake

Cheers,
Thorben

1 Like

Hi, I’m hoping to test the Delegates independently, purely asserting the behaviour within them. The idea would be to pass in the delegateExecution to the Delegate class, where some variables would be read/updated, and then assert these updated variables in the output. Is thispossible in a pure ‘unit’ test, not a ‘scenario’ (integration) test? Thanks