DEV Community

Cover image for Add initial testing to Camunda with Spring Boot 🍃
Thomas Gotwig
Thomas Gotwig

Posted on

Add initial testing to Camunda with Spring Boot 🍃

Let's add a test to our application so that we don't have to confirm things like the User Task manually! As well as some assertions to know what got executed and what not.

Here you can find the code for this chapter under the git tag chapter-2.

For doing the assertions we need:

<dependency>
  <groupId>org.camunda.bpm.assert</groupId>
  <artifactId>camunda-bpm-assert</artifactId>
  <version>8.0.0</version>
  <scope>test</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode

And there is our final happyPath test which goes through all we did from the last article automatically! 🤗

@SpringBootTest
class MainDelegateTest {

    @Autowired private RuntimeService runtimeService;

    @Autowired private ManagementService managementService;

    ProcessInstance pi;

    @BeforeEach
    public void beforeEach() {
        pi = runtimeService.startProcessInstanceByKey(
                "loanApproval");
        assertThat(pi).hasPassed("StartEvent_1")
                .hasNotPassed("Task_0dfv74n")
                .isNotEnded();
    }

    @Test
    public void happyPath() {
        completeTask().hasPassed("Task_0dfv74n").isEnded();
    }

    private ProcessInstanceAssert completeTask() {
        complete(task());
        return assertThat(pi);
    }
}
Enter fullscreen mode Exit fullscreen mode

loanApproval is from loanApproval.bpmn which you can find inside the Camunda Modeler when nothing is selected 🖼️

complete(task()) are two static functions which are doing the clicking on Complete part from the last article for you 🤖

Discussion (0)