Unit Testing of BPMN Processes

1. Testing BPMN Business Process Implementations

With the addition of Camunda as the BPMN engine, the project now supports writing unit tests for processes.

Currently, tests can only be written within the ecos-process microservice; support for writing tests in other projects is planned for the future.

The following libraries are used to simplify BPMN unit testing:

2. Testing Citeck BPMN Components

Tests written to verify Citeck BPMN components consist of small BPMN processes that implement use cases for Citeck components, followed by running the process and verifying the results.

The tests are located in the ecos-process microservice at src/test/java/ru/citeck/ecos/process/domain/bpmn/elements and are written in the GivenWhenThen style.

Every component is expected to be covered by tests. At the time of writing, approximately 40 tests have been written.

2.1 BPMN Unit Test Example

Verifying userTask assignment by role.

Process:

../../../../_images/process_unit_example.png

Unit test:

BPMN unit test
@Test
fun `task assignment by roles`() {
    val procId = "test-user-task-role"
    saveAndDeployBpmn(USER_TASK, procId)

    `when`(process.waitsAtUserTask("userTask")).thenReturn {
        assertThat(it).hasCandidateUser(USER_IVAN)
        assertThat(it).hasCandidateUser(USER_PETR)

        assertThat(it).hasCandidateGroup(GROUP_MANAGER)
        assertThat(it).hasCandidateGroup(GROUP_DEVELOPER)
        it.complete()
    }

    run(process).startByKey(procId, variables).execute()

    verify(process).hasFinished("endEvent")
}

This verifies that when the userTask component is executed, the task is assigned to the correct users and groups based on the specified roles.