Can't check the order of activities

I am trying to extend test case for camunda and JUnit5. I am getting the following error - Illegal call of execute(job = ‘null’) - must not be null! java.lang.IllegalArgumentException: Illegal call of execute(job = ‘null’) - must not be null!

@ExtendWith(ProcessEngineExtension.class)
public class SimpleTestCase {

    @Deployment(resources = {"testProcess.bpmn"})
    @Test
    public void shouldExecuteProcess() {

        // Given we create a new process instance
        ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("testProcess");
        // Then it should be active
        assertThat(processInstance).isActive();
        // And it should be the only instance
        assertThat(processInstanceQuery().count()).isEqualTo(1);
        // And there should exist just a single task within that process instance
        assertThat(task(processInstance)).isNotNull();

        ProcessEngineTests.execute(ProcessEngineTests.job());

       BpmnAwareTests.execute(BpmnAwareTests.job());
        // When we complete that task
        complete(task(processInstance));
        // Then the process instance should be ended
        assertThat(processInstance).isEnded();
        //then
        //Checking the run queue
      	assertThat(processInstance).hasPassedInOrder(new String[] { "UserTask_1","UserTask_2"});
    }

testProcess.bpmn (3.0 KB)

Hi @Denis_Murashko,

to test the user tasks and excute them in your test, you have to write:

assertThat(processInstance).isWaitingAt("UserTask_1"); // maybe more assertions like task().isAssignedTo("user")
complete(task());

Have a look at all posibble assertions and helpers: camunda-bpm-assert/User_Guide_BPMN.md at master · camunda/camunda-bpm-assert · GitHub

Hope this helps, Ingo

1 Like

Hi,@ Ingo_Richtsmeier,
I added lines, but it’s not work.


line 41 - assertThat(processInstance).isWaitingAt(“UserTask_1”);

Hi @Denis_Murashko,

from a first glance at the stack trace this could be an issue with an incompatible assert library version. Please check your versions against this matrix: Testing | docs.camunda.org

Hope this helps, Ingo

Thanks @Ingo_Richtsmeier , i changed library version and added isWaitingAt. I had an error Expecting ProcessInstance {id=‘4’, processDefinitionId=‘testProcess:1:3’, businessKey=‘null’} to be ended, but it is not! and many answers recommend doing ProcessEngineTests.execute(ProcessEngineTests.job()); Can you show the material that describes when to add execute(job())?

    ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("testProcess");
    // Then it should be active
    assertThat(processInstance).isActive();
    // And it should be the only instance
    assertThat(processInstanceQuery().count()).isEqualTo(1);
    // And there should exist just a single task within that process instance
    assertThat(task(processInstance)).isNotNull();

    assertThat(processInstance).isWaitingAt("UserTask_1");
    // When we complete that task
    complete(task(processInstance));
    assertThat(processInstance).isWaitingAt("UserTask_2");
    complete(task(processInstance));
    // Then the process instance should be ended
    assertThat(processInstance).isEnded();
    assertThat(processInstance).hasPassedInOrder("UserTask_1","UserTask_2");

Hi @Denis_Murashko,

This is a missing piece in the documentation. It should be somewhere between “Transaction in Processes” and “Job Exectutor”.

But in short:

execute(job()) is used in a test when

  • the process instance waits at a timer event
  • an attached boundary timer event should be fired
  • a service task is marked as “Asynchronous before”.

Hope this helps, Ingo

2 Likes

@Ingo_Richtsmeier thank you very much man… I was trying to do this with execute(job()) but it did not work and I had this timer there and it was nightmare to find the error… thank you very much!!!