An extension to the standard DMN testing framework shipped with the Camunda Engine that allows to gauge coverage of decision rules.
The Camunda Dmn Test Coverage project extends on the standard JUnit-based DmnEngineRule allowing for coverage and rule matching statistics to be asserted via standard JUnit. It aims to have a concise API with a shallow learning curve that operates in conjunction with the well established JUnit testing framework.
Below an example of a successful test run, a mis-matched rule and a coverage assertion error. Notice the "Execution summary" table logged to better understand which rules have been executed as part of the evaluation.
Cross-platform installation of the library can be obtained via maven 3 with the command:
mvn clean install
Importing the library is equivalent to the usual Camunda native DmnEngine rule prepending with the word Coverage
:
import org.camunda.bpm.dmn.engine.CoverageDmnEngineRule;
Initialising the Rule
consists of:
@Rule public CoverageDmnEngineRule dmnEngineRule = new CoverageDmnEngineRule();
And finally, using for assertions:
...
import static org.junit.Assert.assertEquals;
...
//Asserts the rules coverage
assertEquals(0.25, dmnEngineRule.getCoverage(), 0.0);
//Asserts the rules matched (triggered)
assertEquals(singletonList("rule1"), dmnEngineRule.getMatchedRules());
It is important to note that the rest of your Unit Tests are not impacted and require no code changes.
There are also some more descriptive assertions shipped with this library. Here is how to use them:
...
import static org.junit.AssertCoverage.assertExactCoverage;
import static org.junit.AssertCoverage.assertRuleMatched;
...
//Asserts the rules coverage is exactly 25%
assertExactCoverage(0.25, dmnEngineRule.getCoverage());
//Asserts the only rule matched (triggered) is "rule4"
assertRuleMatched("rule4", dmnEngineRule.getMatchedRules());
For more examples and usage, please refer to the SampleUsageTest.java
file in the repository.
To develop and contribute to the library it is necessary to have:
- Oracle or Open JDK version 8 or greater
- Apache Maven version 3
- Git
make install
Antonio Cucchiara – GitHub: AntoCuc - Mail: antonio_cuc@yahoo.co.uk
Distributed under the MIT license. See LICENSE.md
for more information.
Note: All code standard checks have been built-in to the install target. Please ensure that the build passes on your local (
mvn clean install
) before pushing changes.
How to contribute:
- Fork it (https://github.com/AntoCuc/camunda-dmn-test-coverage)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request