Testing Decisions with the DMN Engine

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

public class DecisionTest {

  @Rule
  public DmnEngineRule dmnEngineRule = new DmnEngineRule();

  @Test
  public void test() {
    DmnEngine dmnEngine = dmnEngineRule.getDmnEngine();
    // load DMN file
    InputStream inputStream = ...;
    //create and add variables
    VariableMap variables = Variables.createVariables();

    DmnDecision decision = dmnEngine.parseDecision("decision", inputStream);
    DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);

    // assert the result
    // ...
  }

}

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

public class DecisionTest {

  @Rule
  public DmnEngineRule dmnEngineRule = new DmnEngineRule(createCustomConfiguration());

  public DmnEngineConfiguration createCustomConfiguration() {
    // create and return custom configuration
    return ...;
  }

  @Test
  public void test() {
    DmnEngine customDmnEngine = dmnEngineRule.getDmnEngine();
    // ...
  }

}

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

On this Page: