Prefer KieHelper over a KieContainer classpath

While testing, the use of a KieContainer classpath—the one you get from invoking KieServices.Factory.get().getKieClasspathContainer()—is not always the best approach. The thing with a KieContainer classpath is that it will scan the entire classpath looking for any META-INF/kmodule.xml file.

If we are only interested in testing a single rule or a subset of the rules present in the application's classpath, there is no need to scan the entire classpath looking for all the kmodule.xml files present.

There are different ways in Drools to create narrow containers with only the specific resources required for the specific scenario that we are testing. Probably, the easiest way is to make use of the org.kie.internal.utils.KieHelper ...

Get Mastering JBoss Drools 6 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.