The community extension Camunda BPM Assert makes it easy to assert the status of your BPMN processes and CMMN cases when driving them forward in your typical unit test methods. Simply write code like
Furthermore a set of static helper methods is provided to make it easier to drive through a process. Based on the 80/20 principle the library reaches out to make those things simple you need really often. You will e.g. often have a a single open task instance in your process instance. Then just write
complete(task(instance), withVariables("approved", true));
The goal? More readable code - less spaghetti tests!
The increased readability will make it much easier to dig through your test code, the next time you need to change it will ultimately come. And your increased efficiency will make your organisational stakeholders happy, too!
Camunda BPM Assert works with all versions of Camunda BPM since 7.0 up to the most recent and all the Java versions (1.6, 1.7., 1.8) still relevant for Camunda BPM installations out there. This is continuously verified by executing around 350 test cases against a travis ci test matrix. In 2014, the library won the Camunda BPM Community Award.
Get started in 3 simple steps!
<dependency> <groupId>org.camunda.bpm.extension</groupId> <artifactId>camunda-bpm-assert</artifactId> <version>1.2</version> <!-- Use 2.0-alpha1 for the CMMN assertions preview! --> <scope>test</scope> </dependency>
Note however, that if you use a Camunda BPM Maven Archetype to create your project, Camunda BPM Assert is already included in your project setup.
2. Add a static import to your test class
Create your test case just as described in the Camunda BPM Testing Guide. As recommended at the end of that guide, add Camunda BPM Assert by statically importing it in your test class:
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*;
3. Start using the assertions in your test methods
You have now access to all the assertions provided by Joel Costigliola's AssertJ rich assertions library - plus the additional Camunda BPM assertions building upon them. Now assume you want to assert that your process instance is actually started, waiting at a specific user task and that task should yet be unassigned, but waiting to be assigned to a user of a specific group? Then write:
assertThat(processInstance).isStarted() .task().hasDefinitionKey("edit") .hasCandidateGroup("human-resources") .isNotAssigned();
Congrats! You are successfully using Camunda BPM Assert. Find a more detailed description of the assertions and helper methods available in the Camunda BPM Assert User Guide.