Camunda tests stop working after asyncBefore flag set to true for bpmn start event

Using tests from official Camunda Github repo: https://github.com/camunda/camunda-bpm-assert

examples folder contains a few bpmn files and tests, by default all works fine, all tests successfully passed, but when I set flag Asynchronous Before for Start event for any bpmn - all asserts start failing.

What is the right way to write tests when bpmn start event executed in async fashion?

If you’ve added an async on an element of the process it commits the current state. Normally the job executor would then pickup the tread itself from there and continue the process but in a testing scenario the job executor is turned off to ensure the test has full control of how the process moves.

What this means for you is that any time there’s an async you need to find the Job that is waiting and complete it.
This is simplified in the testing framework - all you should need is this

execute(job());

You’ll find more details in the docs: https://github.com/camunda/camunda-bpm-assert/blob/master/docs/User_Guide_BPMN.md#helpers-execute

Hi @Niall thank you for reply!

where exactly I should put

execute(job())

For example, I tried to execute the job after process started:

@Test
  @Deployment(resources = { "camunda-testing-job-announcement.bpmn", "camunda-testing-job-announcement-publication.bpmn" })
  public void should_not_fail_if_processInstance_is_waiting_at_expected_task() {
    final ProcessInstance processInstance = startProcess();
    
    execute(job());

    assertThat(processInstance).task(findId("Stelle beschreiben")).isNotAssigned();
  }

but I am getting the following error:


java.lang.IllegalArgumentException: Illegal call of execute(job = 'null') - must not be null!

It depends on where the async is in your model.
You can first assert that you’re waiting at the place where the async is and then complete the job

@Niall, as you may see on the screenshot I have added async before flag for Start event (“Freie Stelle gemeldet”).

You should add it after.

@Niall , what do you mean? Instead of using “Asynchronous before” flag for my particular case I need to use “Asynchronous After” flag, am I right?