I have medium level experience on unit testing and now I’m learning about .

As far as I can see, a NUnit passes by if you don’t Assert. method.

In my test case, I want it to fail by default unless I call Assert. method.

How can I do that if it’s possible?

Simplified Example

Current behavior:

// This test passes
public void Test1()
{
}

// This test fails
public void Test1()
{
    Assert.Fail();
}

The behavior I want:

// This test must fail
public void Test1()
{
}

// This test must pass
public void Test1()
{
    Assert.Pass();
}

Detailed Example for curious cats

The last line of this test looks unnecessary to me. I would like to remove Assert.Fail() call at the end if it was possible to mark the test as “fail by default” somehow. Maybe a parameter for [Test] attribute???

[Test]
public void SetValue_RaisesChangedEvent()
{
    var Property = new Property();
    Property.Changed += (Sender, Args) => Assert.Pass();

    Property.SetValue(1);
    Assert.Fail();
}



Source link https://sqa.stackexchange.com/questions/32480/how-to-fail-nunit-test-by-default-i-want-to-call-assert-pass-when-it-should-pas

LEAVE A REPLY

Please enter your comment!
Please enter your name here