Zero division does not throw exception in nunit

Posted by Boris on Stack Overflow See other posts from Stack Overflow or by Boris
Published on 2010-05-31T19:43:21Z Indexed on 2010/05/31 19:53 UTC
Read the original article Hit count: 284

Running the following C# code through NUnit yields

Test.ControllerTest.TestSanity: Expected: <System.DivideByZeroException> But was: null

So either no DivideByZeroException is thrown, or NUnit does not catch it. Similar to this question, but the answers he got, do not seem to work for me. This is using NUnit 2.5.5.10112, and .NET 4.0.30319.

    [Test]
    public void TestSanity()
    {
        Assert.Throws<DivideByZeroException>(new TestDelegate(() => DivideByZero()));
    }

    private void DivideByZero()
    {
        // Parse "0" to make sure to get an error at run time, not compile time.
        var a = (1 / Double.Parse("0"));
    }

Any ideas?

© Stack Overflow or respective owner

Related posts about c#

Related posts about nunit