Junit Failling

Hello Team ,

  1. assertThat(pVariablesInReturn).isStarted();

  2. assertThat(pVariablesInReturn)
    .hasPassed(“end_event”)
    .isEnded();
    test case is failing in 2 point
    getting this exception
    java.lang.AssertionError: Expecting org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl@7e06727f to have passed activities [end_event] at least once, but actually we found that it passed [StartEvent_1]. (Please make sure you have set the history service of the engine to at least ‘activity’ or a higher level before making use of this assertion!)
    any suggestion ?

Hello @Krishan_Pratap_Singh ,

I am missing some context here. Could you provide us with the BPMN File containing the process you want to test here?

Jonathan

@Krishan_Pratap_Singh Refer this page: Testing | docs.camunda.org and Testing Entire Process Paths - Camunda

You should set history level for testing processes in src/test/resources/camunda.cfg.xml like below:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration"> 
    <property name="history" value="full" />
    <property name="expressionManager">
      <bean class="org.camunda.bpm.engine.test.mock.MockExpressionManager"/>
    </property>
    <property name="processEnginePlugins">
      <list></list>
    </property>
  </bean>
</beans>

Otherwise you can set the history level at test method using annotation:

public class MyBusinessProcessTest {

  @Rule
  public ProcessEngineRule processEngineRule = new ProcessEngineRule();

  @Test
  @Deployment
  @RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
  public void ruleUsageExample() {
    RuntimeService runtimeService = processEngineRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");

    HistoryService historyService = processEngineRule.getHistoryService();
    // requires history level >= "activity"
    HistoricVariableInstance variable = historyService
      .createHistoricVariableInstanceQuery()
      .singleResult();
      
    assertEquals("value", variable.getValue());
  }
}
1 Like

Hi @Krishan_Pratap_Singh,

in this case the message

is misleading in most cases. Your process is likely to wait somewhere in between, before the end event.

A good way to visualize this is enableing the process test coverage: GitHub - camunda-community-hub/camunda-bpm-process-test-coverage: Community Extension Helper library to visualize which parts of a BPMN process have been covered by a unit test.

With this tool you can see which tasks are already covered by your test and where your process instance is stuck.

My guess is that you checked some service task with Async Before and you have to execute the job explicitly to contine the process instance.

Hope this helps, Ingo

1 Like

@Ingo_Richtsmeier @aravindhrs @jonathan.lukas correct I am using camunda:asyncBefore=“true”

RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstanceWithVariables pVariablesInReturn
= runtimeService.createProcessInstanceByKey(“Prcess name”)
.setVariable("'Some vale")
.executeWithVariablesInReturn();

assertThat(pVariablesInReturn)
.hasPassed(“end_event”)
.isEnded();
before that it is working after using asyn=true after that getting error

@Ingo_Richtsmeier orrect I am using camunda:asyncBefore=“true” ,
before that it is working after using asyn=true after that getting error
plz help me where i have to change in unit test

Hi @Krishan_Pratap_Singh,

enter

assertThat(pVariablesInReturn).isWaitingAt("actvityIdWithAcyncBefore");
execute(job()); 

between the start and the end of the process instance in your test.

You can read more about the details here: Transactions in Processes | docs.camunda.org

The shortcut in camunda-bpm-assert is documented in the github repository: camunda-bpm-assert/User_Guide_BPMN.md at master · camunda/camunda-bpm-assert · GitHub.

Hope this helps, Ingo

2 Likes

yes…it’s work for me

1 Like