开发者

NUnit & Exceptions

开发者 https://www.devze.com 2023-03-31 20:08 出处:网络
Is there anyway one can output to the console 开发者_开发问答the message of an exception that may be throw during an NUnit test? Currently I use the ExpectedExceptionAttribute but that doesn\'t output

Is there anyway one can output to the console 开发者_开发问答the message of an exception that may be throw during an NUnit test? Currently I use the ExpectedExceptionAttribute but that doesn't output the message itself, only checks it.


If Method doesn't throw test fails. If it throws it additionally writes exception message to the console.

[Test]
public void Method_throws_exception()
{
    var ex = Assert.Throws<InvalidOperationException>(sut.Method);

    Console.WriteLine(ex.Message);
}

That assert is only at tab tab with http://nuget.org/List/Packages/NUnit.Snippets


I use:

[Test]
public void SomeTest(){
  try {
         ... stuff ...

       Assert.Fail("ExpectedExceptionType should have been thrown");
  } catch (ExpectedExceptionType ex) {
    Console.WriteLine(ex);
    // Assert.Stuff about the exception
  }
}

However I've just noticed NUnit 2.6 and it's Exception Assertion helpers.

0

精彩评论

暂无评论...
验证码 换一张
取 消