JUnit Testing & Mock Service Task

Has anyone mocked service task successfully using MockExpressionManager or anything in Spring Boot (Java)?

Hi Bihan,

It really depends. One way of mocking could be to replace serviceTaskBehavior during process parsing.
https://flowable.org/docs/userguide/index.html#advanced_parseHandlers

Regards
Martin

Hey @Bihan,

If you are using Spring Boot then I presume that you are using either a delegateExpression with a Spring bean or you are using an expression where you use your bean. This means that you could mock those beans by using @MockBean from Spring Boot. Have you tried using that?

Cheers,
Filip

Yes, i am using delegateExpression. If possible can you give a simple sample on how to do it with @MockBeans for flowable.

I have tried with MockExpressionManager(), but this did not worked. My test runs the actual service task instead of the mock. I have discussed about it here Testing processes with junit in spring

Hey,

Have you tried the standard way of working with @MockBean? You inject the bean and annotate it with @MockBean. Something like (test annotations are missing):

public class MyTest {

    @MockBean 
    @Autowired
    private MyDelegate myDelegate;

    @Test
    public void myTest() {
        // Do your thing
    } 
}

Cheers,
Filip

Yes, I know this. Actually what i am asking is how does the process engine know that it should use the mocked service task not the actual service task . In similar testing with MockExpressionManager() provided by flowable itself, the process engine was unable to use mocked service task.

If @MockBean is used then the Spring Application context knows that the bean is a mock. The Process Engine uses the ApplicationContextElResolver to get the bean.

1 Like

Solved the problem. Thanks