How to mock process engine

Hello everyone,
I’m trying to mock process engine because I want to do some unit testing of camunda BPMNs.

Here is part of my code:

@RunWith(MockitoJUnitRunner.class)
 public class ExampleUnitTest {

 @Mock
 public ProcessEngine processEngine;


 @Test
 public void regularTest()
 {
     RuntimeService runtimeService = processEngine.getRuntimeService();
     ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(ProcessNameUtils.EXAMPLE);

     assertThat(processInstance).isStarted();
 }

}

I’m getting null pointer exception on getRuntimeService() method.
Does anyone know how to fix this issue?

Thank you in advance!

Hi @hedza06,

If the processEngine variable is null, then your Mockito setup is most likely not correct yet. Mocking a ProcessEngine object is no different from mocking any other Java object, so there is nothing special to account for.

Cheers,
Thorben