How to run integration tests for BPMNs that include service task (workers)

My team is using Camunda 8 in production and we are planning to add integration tests.
We want to achieve the following integration test functionality:

  • Test deployment of BPMN (please find attached) to zeebe
  • Test the start and completion of BPMN workflows that include service tasks (validate the execution of database calls to a dockerized datastore as part of the worker implementation)

I am using zeebe-process-test-extension maven dependency to spin up an embedded zeebe engine i.e. @ZeebeProcessTest and its assertions
The BPMN to be tested has a service task that queries a documentdb datastore that is running in docker.
Here is the code:

@Test
**public** **void** test_processInstanceCreationByProcessId() **throws** InterruptedException, TimeoutException {

ProcessInstanceEvent event = zeebeClient.newCreateInstanceCommand()

.bpmnProcessId("Process_0mk1o69")
.latestVersion()
.variables(Collections.*singletonMap*("id", "12345678"))
.send()
.join();

ProcessInstanceAssert assertions = BpmnAssert.*assertThat*(event).isActive();

completeServiceTask("stepFrequencyConditionWorker");

ProcessInstanceAssert assertions1 = BpmnAssert.*assertThat*(event).hasVariableWithValue("hasConditionMet", **false**).isCompleted();

}

private void completeServiceTask(final String jobType)
			throws InterruptedException, TimeoutException {
		completeServiceTasks(jobType, 1);
	}

	private void completeServiceTasks(final String jobType, final int count)
			throws InterruptedException, TimeoutException {

		final var activateJobsResponse = zeebeClient.newActivateJobsCommand().jobType(jobType).maxJobsToActivate(count).send().join();

		final int activatedJobCount = activateJobsResponse.getJobs().size();
		if (activatedJobCount < count) {
			Assertions.fail(
					"Unable to activate %d jobs, because only %d were activated."
					.formatted(count, activatedJobCount));
		}
		for (int i = 0; i < count; i++) {
			final var job = activateJobsResponse.getJobs().get(i);
			zeebeClient.newCompleteCommand(job.getKey()).send().join();
		}
		waitForIdleState(Duration.ofSeconds(5));
	}

This code test process “Process_0mk1o69” that I have deployed to the embedded zeebe engine as a part of the integration test.
Inside completeServiceTasks(), I have passed the jobType as per the worker implementation in src/main/java folder.
I want to test the actual execution of that worker and do not wish to mock it as this is an integration test.

After running the test, the embedded zeebe engine comes up fine, the BPMN gets deployed correctly and the process instance starts but instead of trigger the above mentioned worker implementation, it triggers a new worker and asserts the output of the BPMN to false.
Which means, it did not pick the correct worker instead ran a new worker of the same jobType.

How can I resolve this and make sure the test picks the worker inside src/main/java folder?

Hi @seattle-classmate - I’m not an expert in testing, but I believe the recommendation is to test your job worker logic in isolation away from the engine (like a regular unit test), and use zeebe-process-test to assert that the job is being invoked at the proper step in the process, and that the process responds as expected with the data returned.

What the job worker does is “unrelated” to the process itself; the process invokes the job worker and waits for a result, error, or timeout. Everything in between the invocation and result doesn’t matter to the process. If you can assert that the job type is being invoked by the process, and test your job worker in isolation, then you’ve covered all the bases.

I’d love to hear others opinions though! As I said, I’m not an expert in testing and would love to learn more myself!