开发者

Generating test cases

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?


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.


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];
    ..
  }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜