문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top