HankTheTank
HankTheTank

Reputation: 585

test all combinations of parameters excluding one specific combination

I want to create tests that tests all combinations of parameters excluding one combination that will have a different expected result.

So far I have come up with

[TestCase(false, false, ExpectedResult = false)]
[TestCase(false, true, ExpectedResult = false)]
[TestCase(true, false, ExpectedResult = false)]
[TestCase(true, true, ExpectedResult = true)]
public bool Test(bool paramA bool paramB)
{
    var target = new MyComand(paramA, paramB);
    return target.CanExecute();
}

// this class is made up, but shows the basic concept
public class MyCommand
{
    bool _preConditionA;
    bool _preConditionB;

    public MyCommand(bool preConditionA, bool preConditionB)
    {
            _preConditionA = preConditionA;
            _preConditionB = preConditionB;
    }

    public bool CanExecute()
    {
        if (_preConditionA == false)
            return false;

        if (_preConditionB == false)
            return false;

        return true;
    }
}

Or with some crazy [TestCaseSource]. Both cases have a problem with the readability for me personally. This gets more complicated when the parameters are not only boolean. I checked into the [Values] and [Combinatorical] attributes, but they don't really work for my case.

Does anybody know any other way to solve this?

Upvotes: 3

Views: 1909

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57327

Does anybody know any other way to solve this?

One possible solution is to use Assumptions to skip the combinations where the arguments are not expected to produce the post condition being checked by the test.

Upvotes: 1

Related Questions