我已经为我的Seam应用程序编写了一些Drools规则,我想知道如何对这些进行单元测试。有没有人有任何示例代码可以告诉我如何去做?
答案 0 :(得分:5)
将以下代码添加到单元测试(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();
答案 1 :(得分:0)
考虑使用Junit TestRule
library测试一些“糖”。