0

I am a newbie in drools and I cannot find any tool for code coverage in .drl files.Not only I want to know which rules are getting fired but also which branch is being taken in the action section.

//sample drl file
rule "name1"
    when
        condition
    then
        if(some condition){ 
            //do something
        }
        else{
            //do other thing
        }
end
rule "name2"
        when
            condition
        then
            if(some condition){ 
                //do something
            }
            else{
                //do other thing
            }
end

The branching in action/Then section is necessary in my case.

Raj Kumar
  • 1
  • 1
  • 1
    You have to write your own. It's not so hard, I did it at my old company and hooked it up into our Jenkins instance for use during our unit/integration testing phases. Basically you just need to use a rule activation listener to tell you when the rule is activated and executes. Then you can figure out which rules do or don't fire. You just need to make sure to register the listener every time you fire your rules. – Roddy of the Frozen Peas May 05 '20 at 18:18
  • I am aware of that, but I also need to know which branches are being taken, in this case, suppose "name1" rule got triggered then i need to about if,if branch is being taken or else baranch, in the corresponding THEN section of the of rule – Raj Kumar May 05 '20 at 18:28
  • I mean, it's not good practice to be doing that kind of branching in the 'then' clause -- it's indicative of the fact that you should've had two rules in the first place. But no you can't get down to that level without doing byte code inspection. The closest you can get is "the 'then' clause was triggered". – Roddy of the Frozen Peas May 05 '20 at 18:31
  • First of all thanks for this quick response @Roddy , that's what I am asking ,Is there any tool that does that? – Raj Kumar May 05 '20 at 18:47
  • Does this answer your question? [Is there any means by which I could evaluate the test-coverage of drl files in Drools rule engine?](https://stackoverflow.com/questions/50645488/is-there-any-means-by-which-i-could-evaluate-the-test-coverage-of-drl-files-in-d) – Armen Hovhannisian May 05 '20 at 19:45
  • Tool recommendations are off topic. There are plenty of byte code interpretation libraries if you want to write your own, but that's a huge task. Reporting just "this rule fired" is much easier and what I convinced my management was sufficient (especially since we refactored our rules that imporperly had branching logic in the 'then' clause.) – Roddy of the Frozen Peas May 05 '20 at 22:22

0 Answers0