生成测试用例
我需要一种算法来根据一组因变量自动生成测试用例。实现语言并不重要。
作为一个简化的示例:
假设我正在测试函数 F(a,b,c,d)
- a 可以是 a1, a2, a3
- b 可以是 b1, b2
- c 可以是 c1, c2, c3
- d 可以是 d1, d2 如果a=a1, d2, d3, d4 if a=a2, d5 if a=a3
如何生成所有参数组合?
[a1、b1、c1、d1] [a2、b1、c1、d3] [a2,b1,c1,d4]
等等?
I need an algorithm to automatically generate test cases based on a set of dependent variables. Implementation language does not really matter.
As a simplified example:
Assume I'm testing function F(a,b,c,d)
- a can be a1, a2, a3
- b can be b1, b2
- c can be c1, c2, c3
- d can be d1, d2 if a=a1, d2, d3, d4 if a=a2, d5 if a=a3
How can I generate all combinations of arguments?
[a1, b1, c1, d1]
[a2, b1, c1, d3]
[a2, b1, c1, d4]
and so on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所看到的正式名称为组合测试。您可以在此处了解更多相关信息。您可以在线找到许多工具,但我使用 CTE-XL 和 < a href="http://download.microsoft.com/download/f/5/5/f55484df-8494-48fa-8dbd-8c6f76cc014b/pict33.msi" rel="nofollow">PICT
它们都不会生成代码,但会为您生成组合。
What you are looking at is formally known as combinatorial testing. You can read more about this here. You can find many tools online but I have good success using CTE-XL and PICT
Neither of them generate code but will generate the combinations for you.
这听起来比较特别。假设您对参数进行了排序,以便一个参数的可能性列表仅取决于“前一个”参数,您应该能够执行以下操作:
getPossibilities
方法将定义参数的条件:This sounds relatively special. Assuming that you ordered your parameters so that the list of possibility for one parameter only depends on the "previous" parameters, you should be able to do something like:
The method
getPossibilities
would define your conditions for the parameters:也许这里的问题和答案中的一些链接可能值得跟进上。您需要问的基本问题是是否值得生成所有组合(可能值得)。 Phadke 的方法允许选择所有组合的良好二次采样子集。这不是详尽的测试,但它提供了很好的覆盖范围。
Perhaps some of the links in the question and answers here might be worth following up on. The fundamental question you need to ask is whether it's worthwhile generating all combinations (it might be). Phadke's approach allows a well-subsampled subset of all combinations to be chosen. It's not exhaustive testing, but it gives very good coverage.