我已经为我的Seam应用程序编写了一些Drools规则,并且想知道如何进行这些单元测试。有人有示例代码可以向我展示如何执行此操作吗?
最佳答案
将以下代码添加到单元测试(JUnit,TestNG等)中:
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new InputStreamReader(getClass().getResourceAsStream( "rules.drl")));
PackageBuilderErrors errors = builder.getErrors();
Assert.assertEquals(0, errors.getErrors().length);
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
StatefullSession session = ruleBase.newStatefulSession(false);
MyFactObject myFact = new MyFactObject();
session.insert(myFact);
session.fireAllRules();
关于unit-testing - 如何对Jboss规则(Drools)规则进行单元测试?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1206443/