用junit进行流口水测试 [英] Drools testing with junit

查看:130
本文介绍了用junit进行流口水测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用junit测试流口水规则的最佳实践是什么?

What is the best practice to test drools rules with junit?

直到现在,我们将junit与dbunit一起使用来测试规则.我们已经将样本数据放到了hsqldb中.我们有几个规则包,到项目结束时,很难提供好的测试输入来测试某些规则而不触发其他规则.

Until now we used junit with dbunit to test rules. We had sample data that was put to hsqldb. We had couple of rule packages and by the end of the project it is very hard to make a good test input to test certain rules and not fire others.

所以确切的问题是,如何将junit中的测试限制为一个或多个特定测试规则?

So the exact question is that how can I limit tests in junit to one or more certain rule(s) for testing?

推荐答案

我个人使用单元测试来测试隔离的规则.我不认为这有什么不对劲,只要您不会因为孤立的规则在起作用,就不会误以为您的知识库在起作用,就会给人以错误的安全感.测试整个知识库更为重要.

Personally I use unit tests to test isolated rules. I don't think there is anything too wrong with it, as long as you don't fall into a false sense of security that your knowledge base is working because isolated rules are working. Testing the entire knowledge base is more important.

您可以使用 AgendaFilter 编写隔离测试a>和StatelessSession

You can write the isolating tests with AgendaFilter and StatelessSession

StatelessSession session = ruleBase.newStatelessSesssion();

session.setAgendaFilter( new RuleNameMatches("<regexp to your rule name here>") );

List data = new ArrayList();
... // create your test data here (probably built from some external file)

StatelessSessionResult result == session.executeWithResults( data );

// check your results here.

代码源: http ://blog.athico.com/2007/07/my-rules-dont-work-as-expected-what-c​​an.html

这篇关于用junit进行流口水测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆