To easily test DMN decisions in a JUnit test, the DMN engine provides aJUnit Rule. The DmnEngineRule creates a new default DMN engine. The DMN engine can be used in test cases to parse and evaluate decisions.

    1. public class DecisionTest {
    2. @Rule
    3. public DmnEngineRule dmnEngineRule = new DmnEngineRule();
    4. @Test
    5. public void test() {
    6. DmnEngine dmnEngine = dmnEngineRule.getDmnEngine();
    7. // load DMN file
    8. InputStream inputStream = ...;
    9. //create and add variables
    10. VariableMap variables = Variables.createVariables();
    11. DmnDecision decision = dmnEngine.parseDecision("decision", inputStream);
    12. DmnDecisionResult result = dmnEngine.evaluateDecision(decision, variables);
    13. // assert the result
    14. // ...
    15. }
    16. }

    If you want to create a DMN engine with a custom configuration, you can passthis to the DMN engine rule.

    1. public class DecisionTest {
    2. @Rule
    3. public DmnEngineRule dmnEngineRule = new DmnEngineRule(createCustomConfiguration());
    4. public DmnEngineConfiguration createCustomConfiguration() {
    5. // create and return custom configuration
    6. return ...;
    7. }
    8. @Test
    9. public void test() {
    10. DmnEngine customDmnEngine = dmnEngineRule.getDmnEngine();
    11. // ...
    12. }
    13. }

    The DmnDecisionResult implements the interfaceList<DmnDecisionResultEntries>. Whereas the DmnDecisionResultEntries implements the interface Map<String, Object>.This allows you to use common List or Map asserts.

    原文: https://docs.camunda.org/manual/7.9/user-guide/dmn-engine/testing/