生成测试用例

发布于 2024-11-27 17:06:35 字数 322 浏览 2 评论 0原文

我需要一种算法来根据一组因变量自动生成测试用例。实现语言并不重要。

作为一个简化的示例:

假设我正在测试函数 F(a,b,c,d)

  1. a 可以是 a1, a2, a3
  2. b 可以是 b1, b2
  3. c 可以是 c1, c2, c3
  4. 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)

  1. a can be a1, a2, a3
  2. b can be b1, b2
  3. c can be c1, c2, c3
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-12-04 17:06:35

您所看到的正式名称为组合测试。您可以在此处了解更多相关信息。您可以在线找到许多工具,但我使用 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.

流心雨 2024-12-04 17:06:35

这听起来比较特别。假设您对参数进行了排序,以便一个参数的可能性列表仅取决于“前一个”参数,您应该能够执行以下操作:

recursiveTestAllCombinations(previousParameters)
{

  if (length(previousParameters) == numberOfParameters)
  {
    performTest(previousParameters)
    return; //end of recursion
  }


  possibilitiesForCurrentParameter = getPossibilities(currentParameterIndex, previousParameters)

  foreach (p in possibilitiesForCurrentParameter)
  {
    parameters = previousParameters
    parameters.append(p);
    recursiveTestAllCombinations(parameters)
  }
}

recursiveTestAllCombinations([])

getPossibilities 方法将定义参数的条件:

getPossibilities(previousParameters)
{
  if (length(previousParameters) == 0)
  {
    return [a1, a2, a3];
  }
  ..
  if (length(previousParameters) == 3)
  {
    if (previousParameters[0] == a1) return [d, d2];
    ..
  }
}

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:

recursiveTestAllCombinations(previousParameters)
{

  if (length(previousParameters) == numberOfParameters)
  {
    performTest(previousParameters)
    return; //end of recursion
  }


  possibilitiesForCurrentParameter = getPossibilities(currentParameterIndex, previousParameters)

  foreach (p in possibilitiesForCurrentParameter)
  {
    parameters = previousParameters
    parameters.append(p);
    recursiveTestAllCombinations(parameters)
  }
}

recursiveTestAllCombinations([])

The method getPossibilities would define your conditions for the parameters:

getPossibilities(previousParameters)
{
  if (length(previousParameters) == 0)
  {
    return [a1, a2, a3];
  }
  ..
  if (length(previousParameters) == 3)
  {
    if (previousParameters[0] == a1) return [d, d2];
    ..
  }
}
雪若未夕 2024-12-04 17:06:35

也许这里的问题和答案中的一些链接可能值得跟进上。您需要问的基本问题是是否值得生成所有组合(可能值得)。 Phadke 的方法允许选择所有组合的良好二次采样子集。这不是详尽的测试,但它提供了很好的覆盖范围。

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.

Phadke's design of experiments approach to select parameter values for testing (software) systems.

In a nutshell, the approach uses minimum, typical and maximum values of test (method) parameters and varies them according to an appropriately chosen Taguchi array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文