C# Class Xunit.PairwiseStrategy.PairwiseTestCaseGenerator

PairwiseTestCaseGenerator class implements an algorithm which generates a set of test cases which covers all pairs of possible values of test function.

The algorithm starts with creating a set of all feature tuples which we will try to cover (see method). This set includes every single feature and all possible pairs of features. We store feature tuples in the 3-D collection (where axes are "dimension", "feature", and "all combinations which includes this feature"), and for every two feature (e.g. "A" and "B") we generate both ("A", "B") and ("B", "A") pairs. This data structure extremely reduces the amount of time needed to calculate coverage for a single test case (this calculation is the most time-consuming part of the algorithm).

Then the algorithm picks one tuple from the uncovered tuple, creates a test case that covers this tuple, and then removes this tuple and all other tuples covered by this test case from the collection of uncovered tuples.

Picking a tuple to cover

There are no any special rules defined for picking tuples to cover. We just pick them one by one, in the order they were generated.

Test generation

Test generation starts from creating a completely random test case which covers, nevertheless, previously selected tuple. Then the algorithm tries to maximize number of tuples which this test covers.

Test generation and maximization process repeats seven times for every selected tuple and then the algorithm picks the best test case ("seven" is a magic number which provides good results in acceptable time).

Maximizing test coverage

To maximize tests coverage, the algorithm walks thru the list of mutable dimensions (mutable dimension is a dimension that are not included in the previously selected tuple). Then for every dimension, the algorithm walks thru the list of features and checks if this feature provides better coverage than randomly selected feature, and if yes keeps this feature.

This process repeats while it shows progress. If the last iteration doesn't improve coverage, the process ends.

In addition, for better results, before start every iteration, the algorithm "scrambles" dimensions - so for every iteration dimension probes in a different order.

ファイルを表示 Open project: AArnott/Xunit.Combinatorial

Public Methods

Method Description
GetTestCases ( int dimensions ) : List

Creates a set of test cases for specified dimensions.

Private Methods

Method Description
CountTuplesCoveredByTest ( TestCaseInfo testCase, int dimension, int feature ) : int
CreateAllTuples ( ) : void
CreateRandomTestCase ( FeatureTuple tuple ) : TestCaseInfo
CreateTestCase ( FeatureTuple tuple ) : TestCaseInfo
CreateTuples ( int dimension, int feature ) : List
GetMutableDimensions ( FeatureTuple tuple ) : int[]
GetNextRandomNumber ( ) : int
GetNextTuple ( ) : FeatureTuple
MaximizeCoverage ( TestCaseInfo testCase, FeatureTuple tuple ) : int
MaximizeCoverageForDimension ( TestCaseInfo testCase, int dimension, int bestCoverage ) : int
RemoveTuplesCoveredByTest ( TestCaseInfo testCase ) : void
ScrambleDimensions ( int dimensions ) : void

Method Details

GetTestCases() public method

Creates a set of test cases for specified dimensions.
public GetTestCases ( int dimensions ) : List
dimensions int /// An array which contains information about dimensions. Each element of /// this array represents a number of features in the specific dimension. ///
return List