Looks close enough to what I tend to do. It could be worth firing off something like the following to double-check that your knowledge base and working memory are as expected prior to each test.
/** * Iterates through the facts currently in working memory, and logs their details. * * @param session The session to search for facts. */ public static void printFacts(KieSession session) { StringBuilder sb = new StringBuilder(); sb.append("\n************************************************************"); sb.append("\nThe following facts are currently in the system..."); for (Object fact : session.getObjects()) { sb.append("\n\nFact: “ + fact.toString()); } sb.append("\n************************************************************\n"); log.info(sb.toString()); } /** * * @return A String detailing the packages and rules in this knowledge base. */ public static String kbaseDetails(KieBase kbase) { StringBuilder sb = new StringBuilder(); for (KiePackage p : kbase.getKiePackages()) { sb.append("\n Package : " + p.getName()); for (Rule r : p.getRules()) { sb.append("\n Rule: " + r.getName()); } } return "Knowledge base built with packages: " + sb.toString(); } On 29 Apr 2014, at 09:47, richardhands <richard.ha...@uk.sopragroup.com> wrote: > I've written a base class to do the heavy lifting of creating all the Kie > resources etc and to give me a stateless session back that my unit tests can > all use. Each test calls the method in this base class to set up stuff, and > then adds facts and globals and does a fireall. > > however, i get random unit test failures. sometimes the suite will work > perfectly, sometimes rule x will fail, sometimes rule f will fail etc. I'm > convinced it's got to be something to do with the way i'm setting up the > initial resources, and maybe they're getting re-used incorrectly from one > test to another (i expect a brand new clean statelesssession on each test) > but i can't see what i'm doing wrong. The documentation around the new Kie > stuff is still being built around how i'm trying to do stuff, so i'm a bit > lost. Each unit test class is designed to test all the rules in on .drl > file, but there can be many .drl files in one package so i don't want to use > the api's for loading a package, i am having to create a filesystem and load > the drl file into it. can anyone see anything obviously wrong in my base > class that might cause this intermittent failure? > > thanks > > > > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Drools-6-Junit-Random-Failures-tp4029379.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users