Getting all combinations for Test

  • Thread starter Thread starter CSharpDeveloper_OXO
  • Start date Start date
C

CSharpDeveloper_OXO

Guest
Hi all,

for an NUnit-Test I want to have all combinations for my Test-Input-Parameters in a special format (see comments below):

public void CombinatorialTest(Condition condition, Types type, bool value1, bool value2)

Condition and Types are enums

I tried with NUnits combinatorial Testing, but as there is a special pattern for my test input, I don't know, if I can get that done with NUnit Combinatorial Testing and tried a pure csharp solution to generate the Test-Input.

Unfortunately, this doesn't generate the right Input correctly and I think its also because the BooleanValues are not combined correctly and returned as single Elements. The job could have been done with nested more nested loops in method Combinations(), but that's also ugly code then:


using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Permutations
{
[TestFixture]
class MyTest
{
[TestCaseSource("Combinations")]
public void CombinatorialTest(Condition condition, Types typeClass, bool value1, bool value2)
{
Console.WriteLine($"Condition: {condition}, TypeClass: {typeClass}, Bool_1: {value1}, Bool_2: {value2}");
// do Asserts later on
}

public static IEnumerable<object[]> Combinations()
{
foreach (var conditionValue in ConditionValues())
{
// Condition.A, Type_A, false, false
// Condition.A, Type_A, false, true
// Condition.A, Type_A, true, false
// Condition.A, Type_A, true, true
// Condition.A, Type_B, false, false
// Condition.A, Type_B, false, true
// Condition.A, Type_B, true, false
// Condition.A, Type_B, true, true
// Condition.A, Type_C, false, false
// Condition.A, Type_C, false, true
// Condition.A, Type_C, true, false
// Condition.A, Type_C, true, true
// Condition.B, Type_A, false, false
// Condition.B, Type_A, false, true
// ...
foreach (var typeClass in TypeClassValues())
{
yield return new object[] { conditionValue, typeClass, BooleanValues().ToArray().Select(x => x), BooleanValues().ToArray().Select(x => x) };
}

// Type_A, Condition.A, false, false
// Type_A, Condition.A, false, true
// Type_A, Condition.A, true, false
// Type_A, Condition.A, true, true
// Type_A, Condition.B, false, false
// Type_A, Condition.B, false, true
// Type_A, Condition.B, true, false
// Type_A, Condition.B, true, true
// ...
// Type_B, Condition.A, false, false
// Type_B, Condition.A, false, true
// ...
foreach (var typeClass in TypeClassValues())
{
yield return new object[] { typeClass, conditionValue, BooleanValues().Distinct(), BooleanValues().Distinct() };
}
}
}

private static IEnumerable<Condition> ConditionValues()
{
yield return Condition.A;
yield return Condition.B;
yield return Condition.C;
yield return Condition.D;
}

private static IEnumerable<Types> TypeClassValues()
{
yield return Types.Type_A;
yield return Types.Type_B;
yield return Types.Type_C;
}

private static IEnumerable<bool> BooleanValues()
{
yield return false;
yield return true;
}
}

enum Condition
{
A,
B,
C,
D,
}

enum Types
{
Type_A,
Type_B,
Type_C,
}
}

Continue reading...
 

Similar threads

C
Replies
0
Views
88
Craig Muckleston (MCPD, MCTS)
C
D
Replies
0
Views
126
DenisAndreevich
D
M
Replies
0
Views
114
Markus Freitag
M
Back
Top