Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

Are you running this Nunit tests inside VS? Try compile and run your tests through Nunit test runner, outside VS.

If you want run inside VS, try some plugins like Resharper, TestDriven.NET.

Take a look at here too: How do I run NUnit in debug mode from Visual Studio?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top