My First Unit Test - delegateExpression in ServiceTask failing

Hello! I am trying to create my first unit test for Flowable and followed the guide here:

I’m able to get my BPMN to load and start, however, I’m getting an error on my first test which is failing because in my BPMN, I have a serviceTask that uses a delegateExpression to reference my JavaDelegate. I’ve been researching how to mock that as a bean and as best I can tell, the way I’ve fleshed out my test file should work but it is not. Here is my test file:

@FlowableTest
@SpringBootTest
@ExtendWith(SpringExtension.class)
@ConfigurationResource("flowable.cfg.xml")
public class CheckAccountTypeServiceTest {
    private RuntimeService runtimeService;
    private TaskService taskService;
    private ProcessEngine processEngine;

    @BeforeEach
    void setUp(ProcessEngine processEngine) {
        this.processEngine = processEngine;
        this.runtimeService = processEngine.getRuntimeService();
        this.taskService = processEngine.getTaskService();
    }

    @MockBean
    @Autowired
    private CheckAccountTypeServiceTask checkAccountTypeServiceTask;

    @Test
    @Deployment(resources = {"processes/account-check-process.bpmn20.xml"})
    void testAccountCheckTask() {
        runtimeService.startProcessInstanceByKey("accountCheckWorkFlowProcess");

        Task task = taskService.createTaskQuery().singleResult();
        assertEquals("Service Task Account Check", task.getName());
    }
}

I have tried this with and without @SpringBootTest and also with and without @ExtendWith(SpringExtension.class)

Here is the relevant BPMN:

        <sequenceFlow id="SequenceAccountCheck" sourceRef="startEvent" targetRef="ServiceTaskAccountCheck" />
        <serviceTask id="ServiceTaskAccountCheck" name="Service Task Account Check" flowable:delegateExpression="${checkAccountTypeServiceTask}">
        </serviceTask>

Here is the error I’m getting:

org.flowable.common.engine.api.FlowableException: Unknown property used in expression: ${checkAccountTypeServiceTask} with Execution[ id ‘5’ ] - definition ‘accountCheckWorkFlowProcess:1:3’ - activity ‘ServiceTaskAccountCheck’ - parent ‘4’

any assistance would be greatly appreciated.

Hey @Burrito,

Looking at your test annotations seems like you are mixing Flowable standalone usage with Spring Boot.

What I would suggest is for you to use @ExtendWith(FlowableSpringExtension.class) instead of @FlowableTest and @ConfigurationResource. Then the mocking should work as expected as the Flowable engine will be part of the Spring context and fetch the beans from there.

Cheers,
Filip