maanantai 23. heinäkuuta 2007

Unit Testing

Since last time I have improved the range checks, done some planning for redundancy and subsumption checks, improved output and made some unit tests. JBoss Rules also changed its name back to Drools, so I'm going to use that name from now on.

I started to create unit tests so that I could make sure that I have covered all the cases for the range checks. Unit testing rules is not that simple since rules are usually fired in groups, and what I need for the testing is to separate the rule or rules that I'm currently testing, and give them only the minimum facts to fire. Debugging the rules is also difficult, at this moment only the RHS (Right Hand Side of the rule) can be debugged. At the same time that I started to think about unit testing Dr. Gernot Starke made a blog entry on subject. I found out about this because Mark Proctor mentioned it in his blog.

For better testing of rules I made a helper object that I pass to Drools as a global fact. With this object I can get the data of all the fired rules, and causes for firings. This kind of data is not normally needed so I'm only using this object for debugging and testing. Whole thing is still under development, but I hope that I can make something useful that might also help others.

My model for AST data is still changing, one reason for this is the new Drools release that has new features that I need to take care of.

Another thing that has given me some headaches is the redundancy and subsumption checks, after a lot of brain work I found out a way to test it. Creating rules seems to be all about asking the right questions. I still find myself thinking like a Java programmer, not like a Drools rule programmer.

I talked with Mark Proctor and asked him for new directions with testing the rules using impact analysis. Next step is to map the data in the RHS part of the rule. At this point Drools has two dialects Java and MVEL, this mapping will start with MVEL and maybe later it also covers Java. I will personally change the dialect used in my tests to MVEL, because it seems practical for rules.