Yes…

 

We’ve used a combination of JUnit, and Easymock to test individual rules.  At a very high level, we do the following:

 

-          In the static setupBeforeClass() method we construct a KnowledgeBuilder, load any necessary rule files, and construct a KnowledgeBase using the KnowledgeBuilder.

-          In the setup() method we initialize any create EasyMock objects, create a KnowledgeSession, attach any globals and setup a KnowledgeBase audit logger (KnowledgeRuntimeLoggerFactory),

-          In the individual test we construct an ArrayList of Command objects to do fact insertion, rule firing, and run a query (to extract inserted or modified facts from the Working Memory) like so:

o        Cmds.add (CommandFactory.newInsert(aFact))

o        Cmds.add(CommandFactory.newFireAllRules())

o        Cmds.add(CommandFactory.newQuery(xxx, yyyy));

-          We batch execute the commands (see session.execute()) and use the ExecutionResults to extract query results.

-          Finally we use the JUnit framework to assert expectations that come out of our ExecutionResults.

 

I’ve left a lot of details out, but if you do Javadoc lookups on the API’s I’ve mentioned above most of it should be clear.

 

We’ve written over 1,000 unit tests this way, and they run quite fast.

 

Macon

 


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Asif Iqbal
Sent: Wednesday, December 02, 2009 6:59 AM
To: rules-users@lists.jboss.org
Subject: [rules-users] Testing individual rules

 

Hi,

 

This is general question, is it possible to test individual rules in a rules file? And using what, I am familiar with JUnit, but have seen Fit being used in examples.

 

regards