You can also implement various listeners, (WorkingMemoryListener, AgendaEventListener, and
other such goodies in package org.drools.event) register them with your session, and make
assertions over the execution data they gather. You can track such things as:
Did rule A fire? How many times?
Did rule A fire on fact B?
You can even go down to the level of "did rule sequence A fire in the right
order?" assertions, but usually such tests are too brittle, and miss the point of
rules anyway. :)
--- On Wed, 12/2/09, Asif Iqbal <Asif.Iqbal(a)infor.com> wrote:
From: Asif Iqbal <Asif.Iqbal(a)infor.com>
Subject: Re: [rules-users] Testing individual rules
To: "Rules Users List" <rules-users(a)lists.jboss.org>
Date: Wednesday, December 2, 2009, 10:15 AM
Thanks will
look into it.
From:
rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of
Pegram, Macon
Sent: 02
December 2009 16:08
To: Rules
Users List
Subject: Re:
[rules-users] Testing
individual rules
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(a)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(a)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
-----Inline Attachment Follows-----
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users