Search code examples
c#nunittestdriven.net

nunit assertexception when debugging


This is a simple question, I came across a scenario which got me thinking about the way I have been debugging NUnit tests.

I have a class similar to this

public class SomeClass {
   public static bool SomeMethod(){
      return true;
   }
}

Now I have a NUnit test like so

[TestFixture]
public class UnitTests
{
   [Test]
   public void TestOne()
   {
      var retval = SomeClass.SomeMethod();
      Assert.IsFalse(retval, "Test Failed"); 
   }
}

When I run the test in Debug I get this exception

AssertException

Part of me is saying this is how it should be, in that NUnit would normally catch this exception as the failure, whereas the other part of me is saying no there should not be an exception here the test should just fail?


Solution

  • Using Assert.IsFalse is expecting False. You can use Assert.IsTrue or Assert.AreEqual(true, retval).

    From MSDN.

    Assert.IsFalse Method - Verifies that a specified condition is false.