# My First Unit Test - delegateExpression in ServiceTask failing

**URL:** <https://forum.flowable.org/t/my-first-unit-test-delegateexpression-in-servicetask-failing/11384>\
**Category:** Flowable Engine\
**Created:** [March 27, 2024, 7:59pm UTC](https://forum.flowable.org/t/my-first-unit-test-delegateexpression-in-servicetask-failing/11384 "2024-03-27T19:59:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Burrito](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@Burrito](https://forum.flowable.org/u/Burrito)\
**Post date:** [March 27, 2024, 7:59pm UTC](https://forum.flowable.org/t/my-first-unit-test-delegateexpression-in-servicetask-failing/11384/1 "2024-03-27T19:59:46Z")

</div>

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

> **[The Flowable API · Flowable Open Source Documentation](https://www.flowable.com/open-source/docs/bpmn/ch04-API/#unit-testing)**
>
> \## The Process Engine API and services

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:

```auto
@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:

```auto
        <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.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [June 12, 2024, 9:18am UTC](https://forum.flowable.org/t/my-first-unit-test-delegateexpression-in-servicetask-failing/11384/2 "2024-06-12T09:18:57Z")

</div>

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
