Camunda-bpm-assert task always returns null

Trying to use JUNIT for camunda-bpm and assertThat(task(instance)) always returns null due to which not able to test the Happy path. Can anyone let me know why does it always return null.package is of org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.

	@Test
	@Deployment(resources= {"firstone.bpmn","secondone.dmn"})
	public void testFlowOne() throws JsonProcessingException, InterruptedException {
	
                 //Creating variables map
		
		
		ProcessInstance instance=runtimeService().startProcessInstanceByKey("ChangeCspWorkFlow",map);
		assertThat(task(instance)).isNotNull(); // Assertion fails as always it returns null 
		
	complete(task(instance),withVariables("Network","Success"));
}

Followed from this URL https://github.com/ingorichtsmeier/camunda-engine-unittest/blob/test-coverage/

Thanks in advance.

Can you upload the models that you’re testing?

Hi @ravii,

I tested to assert a task like you did and it worked for me.

Do you have any Asynchronous Before checked or other wait states before your process instance reaches the user task?

Having a look at the model (as Niall proposed) would help.

Cheers, Ingo

@Niall,@Ingo_Richsmeier- Can the bpmn file be shared over mail ?

Hi @ravii,

you can use the message button on the profile page.

Hi @ravii,

as there are no user tasks or other wait states in your process, you can’t assert anything except the finished process.

Usually a test would look like

ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("processID", withVariables("var1", value1));
assertThat(processInstance).isEnded().hasPassed(findId("My expected end event"), findId("my important task"));

Hope this helps, Ingo

Hi @Ingo_Richtsmeier Does that mean i can’t use complete() method to force the testing of happy path ?

Hi @ravii,

I would state it in the different direction: In your process there is no need to complete the tasks by yourself.

If you want to contol it, you can include wait states, as described in this best practice: https://camunda.com/best-practices/dealing-with-problems-and-exceptions/#additional-save-points.

With this save points you have call

execute(job());

to continue the process execution in your tests.

Hope this helps, Ingo