DEV Community

Cover image for Add initial testing to Camunda with Spring Boot πŸƒ
Thomas Gotwig
Thomas Gotwig

Posted on

3 2

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 πŸ€–

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post β†’

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more