Test hasVariables-Check after process instance is ended

Hi,

I would like to write JUnit-Tests for my process model with camunda-bpm-assert. Therefore, I would like to check some values of my variables after the process instance is already finished.

Trying to do that my assert-statement looks like that:

assertThat(processInstance) //
.hasPassed(“StartEvent1”) //
.hasNotPassed(“EndEvent1”) //
.hasVariables(“s”) //
.isEnded(); //

Unfortunatelly, the following exception occurs:

java.lang.AssertionError: Expecting assertion to be called on non-null current state of actual org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl@68d651f2, but found it to be null!
at org.camunda.bpm.engine.test.assertions.AbstractProcessAssert.getExistingCurrent(AbstractProcessAssert.java:49)
at org.camunda.bpm.engine.test.assertions.ProcessInstanceAssert.hasVars(ProcessInstanceAssert.java:274)
at org.camunda.bpm.engine.test.assertions.ProcessInstanceAssert.hasVariables(ProcessInstanceAssert.java:257)

I was wondering if you please could tell me the right way for executing my variable-check? If you need further information do not hesitate to contact me.

Thank you in advance

Hi @le00n,

once the process instance is finished, you have to write

assertThat(processInstance).isEnded().variables().containsKey("s");

or maybe

assertThat(processInstance).isEnded().variables().contains(entry("s", myExpectedValue));

Any assertJ assertions on Maps are possible.

Hope the helps, Ingo

1 Like

Hi @Ingo_Richtsmeier,

thank you for your quick answer. It turns out that I used an old version:

org.camunda.bpm.extension camunda-bpm-assert 1.2 test

Switching the version of 1.2 to 2.0-alpha2 worked for me.

Hi @le00n,

the camunda-bpm-assert library moved from community extension to be part of the product.

You can find details about the current version and it’s compatibility here: https://docs.camunda.org/manual/7.13/user-guide/testing/#camunda-assertions

and here: https://docs.camunda.org/manual/7.13/user-guide/testing/#assertions-version-compatibility

Hope this helps, Ingo