Coverage with Junit5

Hello,
I am trying to port to Junit5 with the coverage library at version 1.0.0 but I am having problems.
My goal is to test the coverage of a process using Spring Boot beans, then initializing the applicationContext first.
While first in the test class I declared

@Autowired
ProcessEngine processEngine

And later I initialized like this:
ProcessEngineTests.init (processEngine);
And then I used the various assertThat () etc …

Now, doing the same thing the engine can’t find the bean springs.
I paste the test class into it for completeness.

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.assertions.ProcessEngineTests;
import org.camunda.bpm.extension.junit5.test.ProcessEngineExtension;
import org.camunda.bpm.extension.process_test_coverage.junit5.ProcessEngineCoverageExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.HashMap;
import java.util.Map;
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*;
import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.runtimeService;

//import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.*;

@SpringBootTest(
        classes = Application.class
)
@ExtendWith(SpringExtension.class)
@ExtendWith(ProcessEngineCoverageExtension.class)
@Deployment(resources = {"project.bpmn"})
public class MyTest {

    public static final String PROCESS_KEY = "project";
    public static final String TASK = "task";

    public ProcessEngine processEngine;
    @Autowired
    public RuntimeService runtimeService;

    @BeforeEach
    public void init() {
        ProcessEngineTests.init(processEngine);
    }

    private ProcessInstance startProcess() {
        return runtimeService().startProcessInstanceByKey(PROCESS_KEY, "bk");
    }

    @Test
    public void shouldExecuteHappyPath() {
        final ProcessInstance instance = this.startProcess();
        
        assertThat(instance).isStarted().isWaitingAt(TASK);
        complete(task());
    }

}

This is the error:

org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${checkInput}. Cause: Cannot resolve identifier 'checkInput'

	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:63)
	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:51)
	at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior$3.call(ServiceTaskDelegateExpressionActivityBehavior.java:107)
	at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior$3.call(ServiceTaskDelegateExpressionActivityBehavior.java:102)
	at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.executeWithErrorPropagation(AbstractBpmnActivityBehavior.java:90)
	at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior.performExecution(ServiceTaskDelegateExpressionActivityBehavior.java:127)

Hi @FurioShow! Thank you kindly for reaching out.

I know @Ingo_Richtsmeier has experience with JUnit5, as he’s the Maintainer for camunda-bpm-junit-5. Perhaps he’ll have some insight as to how to resolve your issue. :slight_smile:

Hi @kiran.oliver ! Thank you for the interest.
I’ve solved the problem with the new library’s version of coverage 1.0.2, especially with use of camunda-bpm-process-test-coverage-starter.
But I’m curious to know how it could be solved without this auto-configured library…

1 Like

Hi @FurioShow.
My reply comes a little late, but maybe you’re still interested in the answer.
I imagine the problem to come from the fact, that the ProcessEngineCoverageExtension uses it’s own process engine. This is due to the fact, that it inherits from the camunda-bpm-junit5 extension.
You then have two process engines. The one in the spring boot app and the one in the extension.
Exactly for this use case (using the engine in the spring boot app), we provided the spring testing and starter modules.
Hope this clarifies things a bit.