用于测试用例制定的流水
我正在测试一个相当复杂的系统,它的行为根据一些业务规则(写为半正式文本)。
目标是创建测试用例,涵盖尽可能多的系统状态。我想通过以下方式自动执行此任务:
1)在 Drools 中形式化业务规则 2)然后使用某种机制创建所有可能情况的列表(需要测试)
例如,我有以下包含两个规则的业务规则包(这只是一个示例,真正的业务规则要复杂得多):
global List outErrorCodes;
global Boolean condition1;
global Boolean condition2;
global Boolean condition3;
rule "01"
when
eval( condition3 == false);
then
outErrorCodes.add("ERROR_CODE1");
end
rule "02"
when
eval((condition1 == true) && (condition2 == true));
then
outErrorCodes.add("ERROR_CODE2");
end
条件1 、条件2和条件3是输入。 outErrorCode 是输出。
也就是说,条件 1、条件 2 和条件 3 描述了某种情况,而 outErrorCode 描述了系统在该特定情况下的预期行为。
我想创建一种机制,它根据规则中的逻辑自动创建所有可能的元组(条件1、条件2、条件3、outErrorCodes)的列表。每个元组代表系统的一个状态。
然后,这些元组将用作创建实际测试用例的基础。
Drools 可以吗?如果是这样 - 怎么办?
提前非常感谢
德米特里
I am testing a rather complex system, which behaves according to some business rules (written as semi-formal text).
The goal is to create test cases, which cover as many states of the system as possible. I want to automate this task in the following way:
1) Formalize the business rules in Drools
2) Then use some mechanism to create a list of all possible situations (which need to be tested)
For example, I have following business rule package with two rules (this is only an example, real business rules are much more complex):
global List outErrorCodes;
global Boolean condition1;
global Boolean condition2;
global Boolean condition3;
rule "01"
when
eval( condition3 == false);
then
outErrorCodes.add("ERROR_CODE1");
end
rule "02"
when
eval((condition1 == true) && (condition2 == true));
then
outErrorCodes.add("ERROR_CODE2");
end
condition1, condition2 and condition3 are inputs.
outErrorCode is the output.
That is, condition1, condition2 and condition3 describe a certain situation, and outErrorCode describes the expected behaviour of the system in that particular situation.
I want to create a mechanism, which automatically creates a list of all possible tuples (condition1, condition2, condition3, outErrorCodes), based on the logic in the rules. Each tuple represents a state of the system.
These tuples will then be used as a basis for creating actual test cases.
Is it possible with Drools? If so - how?
Many thanks in advance
Dmitri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们成功地获取了规则集,使用 drools-server 将其部署为服务,然后编写一个脚本来进行 Web 服务调用,以运用每个输入变量的每个可能值。在大约一个小时内,我们能够对规则库进行 5000 多次调用,并查看每种情况的输出。
缺点(我认为您不会用任何解决方案来解决这个问题)是您正在测试业务逻辑。当您考虑一下时,您可以生成所需的所有测试数据,但如果不运行业务逻辑(您正在测试),则无法生成测试输入和预期结果。只是说,如果您自动生成业务逻辑的输入,您实际上无法在不违反测试完整性的情况下知道预期结果。
We had success in taking the ruleset, deploying it as a service using drools-server, and then writing a script to make web service calls exercising each possible value of each input variable. Within about an hour we were able to make 5000+ calls to our rule base and see output for each case.
The downside (and I don't think you will get around this with any solution) is that you are testing business logic. When you think about it, you can generate all the test data you want, but you can't generate test input and an expected result without running the business logic (which you are testing). Just saying that if you get into auto generating input to business logic, you can't actually know the expected results without violating the integrity of the test.