Testing DMN Tables Automatically

By
happy woman in front of laptop
  • Blog
  • >
  • Testing DMN Tables Automatically
TOPICS

30 Day Free Trial

Bring together legacy systems, RPA bots, microservices and more with Camunda

Sign Up for Camunda Content

Get the latest on Camunda features, events, top trends, and more.

TRENDING CONTENT

One key feature of DMN tables is that they enable business people to provide Business Rules in an intuitive way – like creating an Excel sheet. As a developer you get the DMNs and you integrate them into the BPMN-Process.

But how can you make sure that DMN works as expected?

With this in mind I started the DMN Table Tester Project with these main goals:

  1. Test the DMNs that I get from businesses, even without knowing the exact rules.
  2. Learning more about DMN Tables🤓.
  3. Playing with interesting technologies😀.

Interested? Then let me show you how it works with this simple DMN:

example DMN for dish

Configure your Test

The Tester provides a simple User Interface that lets you define a DMN Test in no time.

  • Decision Id
    • The Identifier of your DMN Table (from the DMN file).
  • DMN Path
    • The Path and Name of your DMN file.
  • Test Inputs
    • You can define every variable you use in your Input Expressions.
    • The values are all possible inputs you can think of.

Here is an example:

configure DMN test example

Run the Test

This shows you that the DMN is correct:

successful DMN test results

Each Test Case is one row, that provides the following information:

  • The test inputs that evaluated the DMN table 
  • The DMN Row that matched for these inputs (this is the row number you find in the Camunda Modeler)
  • The Inputs that matched (the inputs you find in the Camunda Modeler)
  • The Outputs that matched (the outputs you find in the Camunda Modeler)

As everything worked — there is not much to do, so let’s add some Bugs😇.

Invalid Input

Having a misspelled input value, gives us the following result. With these warnings you find the typo on first sight.

DMN test typo warning

Another example is the following. Here we missed the boundary case. Together with the valid tests for “Spring” we see that we used < 4 instead of ≤ 4.

missed the boundary case test result
missed boundary case DMN

Ok here is now the test — do you see the problem😀:

DMN test results table
test DMN table

Solution: we have 5 not included with (5..8] — we need [5..8].

Invalid Output

So what can go wrong with outputs? The only thing that I can think of is the type and its formatting (let me know if you have other cases😬!). 

Here is an example:

missing apostrophes invalid output

This one is a bit trickier, but you will see that the Apostrophes (“) are missing.  Or did you fail to provide a variable with the name ‘Stew’, as the error message suggests?

By the way, after studying this error message I now know why these tedious apostrophes are needed! 

Invalid Match Results

If you use the Hit Policy UNIQUE, the DMN Tester can help you even more.

Hit Policy UNIQUE DMN Tester

You see that with a guest count of 5 we have two matches. The same result with the Hit Policy FIRST:

DMN test results table

You’ll see, it’s hard to say if this is what you wanted.

Test Case Creation

As you can imagine, the number of Test Cases can be overwhelming. So what we can do is to mark every Result that is correct and persist it to the DMN Configuration.

Just check the validated (correct) Rows and hit the blue button:

check the validated Rows and hit the create test cases button

Running the Tests again gives you now the following result:

check valid rows result DMN test result

The DMN Row and the outputs are now checked if they haven’t changed. So if we change our DMN, that changes the Result, and we see this right away:

updated DMN result

Bonus: Test Driven Development

We covered so far, more or less, the Use Cases where the Process Responsible gets the DMN and checks if it is valid.

Is it also possible to write the Test first and then add the Rule – so called Test Driven Development?

Spoiler: Of course! Let’s have a look:

empty DMN for dish

Our DMN is empty of course. We define the first Rule in the DMN Config Editor:

define Rule in DMN Config Editor

As expected there is no Rule yet:

test result with no rule

After adding the Rule:

DMN after adding rule

The Rule matches and we can go to the next Rule.

matching rule test

Voilà — we can now develop our DMNs step by step and, of course, add TDD to our CV😉.

Conclusion

The DMN Table Tester should give you the power to:

  • Validate a DMN efficiently
  • Develop your DMN ‘Test-Driven’
  • Add regression Tests on the fly
  • Plus, it’s a tool you can give to your Business People to explain problems, or at least communicate with them

Still interested? Try it out, I created a step-by-step tutorial in the original Blog post.

If you want to check out how it is done, find out on GitHub.

Thanks goes to Philipp Ossler for helping me adding the needed functionality in the excellent dmn-scala project.

About the Author

Pascal Mengelt is a Software Engineer with nearly two decades’ experience. He works for finnova AG Bankware in Seewen SZ, Switzerland, helping customers to digitalize their processes on finnova’s Open Platform.  Get in touch on Medium / GitHub or [email protected].

Start modelling business process workflows using BPMN

Try All Features of Camunda

Related Content

An integral part of process orchestration is process automation—get those repeatable, well-understood tasks that don't require complex decision-making on autopilot!
Enhance your business's operational efficiency with business process management, and streamline your workflows to reduce cost and minimize risk.
Transition smoothly from design to implementation with an end-to-end business process. We'll show you how!