Anand S
Anand S

Reputation: 760

Ignore a nunit test based on the data that is loaded in TestCaseSource

I would like to ignore a test based on the input given to the test , I searched around and found couple of solutions,They are as follows

Assert.Ignore();
Assert.Inconclusive();

But what i need is it should ignore only when i passed the true value something like

Assert.Ignore(true);

I did achieve what i wanted using the conditional statement like the following

if(ignoreTheTest)
{
Assert.Ignore();
}

i feel some what this is not best way of doing this , i want to know if there was a better way doing it.Thank you in advance :).I am just starting out ,sorry with the novice que

Upvotes: 1

Views: 271

Answers (1)

Michael Mairegger
Michael Mairegger

Reputation: 7301

I have never used this, but if your complaint is about the if-statement that you have to write every time I would suggest you to extract the code into a method::

public static void Assert(Func<bool> cond, string message = "")
{
    if(cond())
    {
        Assert.Ignore(message);
    }
}

Upvotes: 1

Related Questions