23 4 comments
Advanced Rule testing
I am happy to write my first post about a topic in Visual Rules projects that is both, the most important thing and often the most neglected one. I am writing about rule testing – or better: creating sustainable tests. I see that especially in the beginning of projects loads of rule tests are created. Which is good. The problem with this schedule however is that during the course of rule development maintaining your tests becomes more time-consuming.
If you have a lot of rule tests structured badly, (regression) testing becomes inconvenient and project participants quickly lose motivation in testing. This post is about an approach lent from software programming, called unit testing. I will show you, how it can be adapted to VR projects and improve the maintainability and scalability of tests. But first it is important to understand, why tests can become a pain if wrongly organized and rule modelers get sloppy with testing.
Rule tests want to be taken care of
Every test case has a direct dependency to a business rule. If the rule´s inputs or outputs change, all test cases need to be adapted. Same goes for the object model. If, e.g., an Integer is converted to a String, you will have to add lots of quotes throughout your rule project.

Refactoring necessary if Integer attribute became a String
Specifiying test inputs can be annoying
Depending on your strictness when defining your inputs and outputs (a very important topic by the way, but that is another story), you have to fill in more or less information. Which ones are important for the test? Filling out all the fields is too time consuming, entering just some might not be enough.

For complex objects, its hard to tell, which parts are needed for the test
Unclear responsibilities
Simple question: Who maintains the tests? Depending on the organization of the project, it can be a modeler or a dedicated tester. A tester would not get permission to change the rule. But if the test is attached to the rule, it would need different permissions for the rule and the test. With modeler and tester in one person, the responsibility issue remains. If global changes of Modeler_A affect rule domains of Modeler_B, Modeler_A would have to change Modeler_B´s rules and tests, to which he might not have permissions.

Responsibilities not clearly split up
Feel free to add points to this list. I´m sure there are more than the currently listed ones. Now, how can you set up your tests in order to eliminate those issues? The answer is surprisingly simple. I will reveal three key changes to you to perform in your rule project:
Grant tests their own project
If testing is as important as stated by everyone, then tests deserve their own rule project. Create a test project and rebuild the package structure of your business logic. Every package in the test project needs to reuse its business logic representation. Both, the rebuild structure and the reuse is depicted below.

The test package reuses the business packages
Create testing rules
Now that you have a dedicated space for testing, you can start setting up test rules. Create a flow rule with the same name as the business rule that you want to test and add “Test” to the name. From your test rule you can now call the business rule. In the example below, the paralells between the projects are visible.

Test Rule with same name as Business Rule
Create rule tests for the testing rules
Create a rule test for your testing rule. When the rule test is executed, the testing rule calls the business rule which delivers the results.
What is the benefit of having a test rule in between? First you can mock or prepare irrelevant data that you don´t want to test. The tester does not need to provide this data in the test editor anymore. If you compare the test editor screenshot below with the one above (asking the question: “This information necessary?”), you can see, how the tester can only alter the parameters necessary for the test.

Test Rule with same name as Business Rule
Some might ask now: The whole thing of creating a new project and additional rules looks like more work. Where is the advantage? It is slightly more work to initially create the test. But loosely coupling business rules and tests eliminates the barriers for testing mentioned above:
Rule tests want to be taken care of
Now, if the data elements or types of the business rule change, it only affects your test rule. You only need to make changes there once, while your test cases can stay the same. Your test rule serves as a buffer between your test definition and your business logic. In the Integer vs. String example, you would simply use a toString() function to convert your test values before the business rule is executed.
Specifiying test inputs can be annoying
Again, the test rule serves as a buffer. No matter how many input parameters you have for your business rule, you can define different input parameters for your test rule. The discrepancy between the two inputs can be mocked, or set to null, or calculated. This can be defined in the test rule between the green start node and the business rule call. The result is a VR test, that only demands the input that can really vary between the single test cases. That makes creating test cases much easier.
Unclear responsibilities
The testing project is of the testers´ responsibility. If the Visual Rules Team Server is used, all testers get read permission for the business logic and read/write permission for the tests. The business modelers´ permissions are set just the other way around. If you don´t have dedicated testers, than the business modelers are responsible for the test project. The advantage then is, that all tests can be found in the test project. No tests can be “overseen”.
Summary: My experience
I have experienced that especially in more complex projects, this approach leads to better defined tests and simply more testing. If it´s because of the concrete advantages mentioned here, or plainly the fact, that there is a VR project in the workspace of the responsible person carrying the label “Test”, I don´t know. I would like to motivate you to try “advanced rule testing” in your projects. The exchange of conventional testing with advanced testing can be done very quickly. When doing, you will see that there are much more advantages that I will point out in a future post. But for now, I guess you´ll have plenty to try. I would be happy to read more about your experience with this approach or testing in VR projects in general. Please comment this post if you have questions or remarks!



Hi Christof
You make many very good points. I believe that in testing that we discover the final set of rules and until you test the rules against operational data, you no amount of analysis can discover the rules. Also the test are critical artifacts for
the project.
Early testing, execution profiling and debugging is key to a successful project. Plus it is a lot of fun!
Tom
Hi Christof,
very good post. You did a good job writing about the tricks and traps of testing. I have some comments to your section with “Specifiying test inputs can be annoying”. As you write it is often unclear which input or output needs to be specified in a rule test. If this is the case shouldn’t a rule author question himself if the rule interface is wrong?
If a rule defines something as input and it doesn’t affect the test then does the rule really need it?
On the other side when two tests for a rule need different inputs or return different outputs, is the rule’s responsibilty wrong, e.g. it is doing more than it was intended to do?
Maybe you can elaborate on this a little bit further, if you aren’t already planning to write a follow up (maybe what you were refering to with “strictness when defining inputs or outputs”). Would like to read your opinion and your experiences about that.
Cheers,
Robert
Hi Robert,
Thanks for your comment and compliments.
Partly I am referring to the strictness of defining inputs and outputs. Modeling business rules is different to programming in many points. One of them is that business modelers often choose defining variables globally in favor of easier modeling. That leads to interfaces that are not too “strict”. A trained programmer, however, knows design patterns that, again, lead to strict interfaces.
The other reason I had in mind was objects. An example: A “Check eligabilty for bonus” rule has the input data element customer : Customer. If certain criteria is fulfilled (customerGroup = 100, isPremiumCustomer=true, etc.) the customer gets a bonus. The address of the customer, however, is not important. If the tester knows that, he can use the rule to set any address and only requests the important fields from the test editor.
But all your points are valid, too, of course. Often, especially with business modelers who are new to Visual Rules and/or programming, the setup of interfaces and the structure of the rule project could be better. But in this case, the tests (not only with the method described but with all ways rule testing) should make it clear, that something is wrong in your package setup or your interfaces.
Once again, thanks for your remarks. Please let me know, if the answer helped, describing the point.