Try this in a NUnit test fixture referencing NUnit.Framework v 2.4.7
// 2.4.7 - test passes even if an exception of wrong type is thrown
[ExpectedException(ExceptionType=typeof(FileNotFoundException))]
[Test]
public void Test_ExpectedException()
{
throw new ArgumentException();
}
I found that the test passes if "any" exception is thrown. It doesn't have to match the specified type. A false positive!
To fix this, upgrade your NUnit version to 2.5.2. You'd also need to fix a compile error. 'ExceptionType' property has now become ExpectedException.
//2.5.2 'works as expected'
[ExpectedException(ExpectedException=typeof(FileNotFoundException))]
[Test]
public void Test_ExpectedException()
{
throw new ArgumentException();
}
You live... you learn.
No comments:
Post a Comment