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:
- Test the DMNs that I get from businesses, even without knowing the exact rules.
- Learning more about DMN Tables🤓.
- Playing with interesting technologies😀.
Interested? Then let me show you how it works with this simple DMN:
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:
Run the Test
This shows you that the DMN is correct:
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.
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.
Ok here is now the test — do you see the problem😀:
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:
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.
You see that with a guest count of 5 we have two matches. The same result with the Hit Policy FIRST:
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:
Running the Tests again gives you now the following 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:
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:
Our DMN is empty of course. We define the first Rule in the DMN Config Editor:
As expected there is no Rule yet:
After adding the Rule:
The Rule matches and we can go to the next Rule.
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].