[rules-users] Testing individual rules

Pegram, Macon zmpegram at choosehmc.com
Wed Dec 2 11:08:18 EST 2009


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 at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Asif Iqbal
Sent: Wednesday, December 02, 2009 6:59 AM
To: rules-users at 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091202/55e10ca0/attachment.html 


More information about the rules-users mailing list