-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
416 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Combinatorial vs. pairwise | ||
|
||
Combinatorial and pairwise are equivalent while using only 1 or 2 parameters in your theory. | ||
For 1-2 parameters, each of these schemes would produce a test case of every combination of every allowed value for each parameter. | ||
|
||
For example, consider this two parameter theory: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#CombinatorialTwoParameters)] | ||
|
||
## Combinatorial testing | ||
|
||
Once you have more than two parameters, the number of test cases grow exponentially in order to cover every possible combination when using @Xunit.CombinatorialDataAttribute. | ||
Consider this test with 3 parameters, each taking just two values: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#CombinatorialThreeParameters)] | ||
|
||
We already have 8 test cases for just 3 @System.Boolean parameters. | ||
With more parameters or more values per parameter the test cases can quickly grow to a very large number. | ||
In general, the exponential function is: | ||
|
||
$$a^p$$ | ||
|
||
Where `a` is the number of allowed possible values for an argument and `p` is the number of parameters. | ||
Or if parameters each have a unique number of possible values, the combinatorial explosion is modeled as: | ||
|
||
$$p_1 \times p_2 \times p_3 \times ...$$ | ||
|
||
Where p<sub>n</sub> is the number of possibles values of the parameter at index `n`. | ||
|
||
## Pairwise testing | ||
|
||
An exponential explosion of test cases can cause your test runs to take too long. | ||
This level of exhaustive testing is often not necessary as many bugs will show up given a combination of just two parameters with particular values. | ||
Pairwise testing focuses on this idea and it generates far fewer test cases than combinatorial testing because it only ensures there is a test case covering every combination of two parameters. | ||
It does this in a clever way that can "compress" the test cases by making each test case significantly test more than one pair. | ||
|
||
To use pairwise testing, use the @Xunit.PairwiseDataAttribute instead of the | ||
@Xunit.CombinatorialDataAttribute: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#PairwiseThreeParameters)] | ||
|
||
We have cut the number of test cases in half by using pairwise instead of combinatorial. | ||
As parameter count rises or allowed values per parameter are more than 2, the test case reduction by switching from combinatorial to pairwise can be much greater. | ||
|
||
Notice that although the test cases are fewer, you can still find a test case that covers any *two* parameter values (thus *pair*wise). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
items: | ||
- name: Features | ||
href: features.md | ||
- name: Getting Started | ||
href: getting-started.md | ||
- href: getting-started.md | ||
- href: combinatorial-vs-pairwise.md | ||
- href: value-sources.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Value sources | ||
|
||
In this article we will generally use @Xunit.CombinatorialDataAttribute. | ||
Please note that @Xunit.PairwiseDataAttribute is equally applicable in all these samples. | ||
|
||
## Enumerable values | ||
|
||
Parameter types with allowed values that can already be enumerated will be provided those values by default. | ||
Consider this case of using @System.Boolean as the parameter type: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#CombinatorialBool)] | ||
|
||
The @Xunit.CombinatorialDataAttribute (or @"Xunit.PairwiseDataAttribute") will supply Xunit with both `true` and `false` arguments to run the test method with, resulting in two invocations of your test method with individual results reported for each invocation. | ||
|
||
Using a C# `enum` type will similarly yield each enum value automatically for test case generation. | ||
|
||
## Custom-supplied values | ||
|
||
To supply your own values to pass in for each parameter, use the | ||
@Xunit.CombinatorialValuesAttribute: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#CombinatorialValues)] | ||
|
||
This will run your test method four times with each of the prescribed values. | ||
|
||
## Values over a range | ||
|
||
To run a test with a parameter over a range of values, we have | ||
@Xunit.CombinatorialRangeAttribute to generate tests over intervals of integers. | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#ValuesOverRange)] | ||
|
||
@Xunit.CombinatorialRangeAttribute has two distinct constructors. | ||
When supplied with two integers `from` and `count`, Xunit will create a test case where the parameter equals `from`, and it will increment the parameter by 1 for `count` number of cases. | ||
|
||
In the second constructor, @Xunit.CombinatorialRangeAttribute accepts three integer parameters. | ||
In the generated cases, the parameter value will step up from the first integer to the second integer, and the third integer specifies the interval of which to increment. | ||
|
||
## Value generated by a member | ||
|
||
The @Xunit.CombinatorialMemberDataAttribute may be used to generate values for an individual Theory parameter using a static member on the test class. | ||
The static member may be a field, property or method. | ||
|
||
A value-generating method is used here: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#GeneratedByMethod)] | ||
|
||
A value-generating property is used here: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#GeneratedByProperty)] | ||
|
||
A value-generating field also works: | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#GeneratedByField)] | ||
|
||
## Randomly generated values | ||
|
||
The @Xunit.CombinatorialRandomDataAttribute can be applied to theory parameters to generate random integer values. | ||
The min, max, and number of values can all be set via named parameters. | ||
|
||
[!code-csharp[](../../samples/GettingStarted.cs#CombinatorialRandomData)] |
Oops, something went wrong.