Replace behaviour for external tasks in tests

Hello. I created simple Camunda spring boot project and also created simple BPMN process with switcher. process.bpmn (5.5 KB)

I used service task with external implementation as a spring beans. I want to write tests for process but I don’t want to test how beans works. Because in general I use external implementation for connection to DB and save parameter to context or REST call to internal apps. For example I want skip execute service task(one) and instead set variables for switcher. I tried to use camunda-bpm-assert-scenario for test process and wrote simple test WorkflowTest.

I noticed if I use @MockBean for One.class then Camunda skip delegate execution. If use @Mock then Camunda execute delegate execution.

PS Sorry for bad english


public class One implements JavaDelegate {
    private final Random random = new Random();

    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("Hello, One!");
        execution.setVariable("check", isValue());

    public boolean isValue() {
        return random.nextBoolean();


@Deployment(resources = "process.bpmn")
public class WorkflowTest extends AbstractProcessEngineRuleTest {

    private ProcessScenario insuranceApplication;

    private One one;

    public void init() {
        Mocks.register("one", one);

    public void shouldExecuteHappyPath() throws Exception {
        // given
        when(insuranceApplication.waitsAtServiceTask("Task_generator")).thenReturn(externalTaskDelegate -> {
                    externalTaskDelegate.complete(withVariables("check", true));

        String processDefinitionKey = "camunda-test-process";
        Scenario scenario =
                .startByKey(processDefinitionKey) // either just start process by key ...

        verify(insuranceApplication, never()).hasStarted("three");
        verify(insuranceApplication, atLeastOnce()).hasStarted("two");

        assertThat(scenario.instance(insuranceApplication)).variables().containsEntry("check", true);