Using NUnit to test for any type of exception

The help for Assert.Throws<> states that it “Verifies a delegate throws a particular type of exception when called”

Try the Assert.That version as it will catch any Exception:

private class Thrower
{
    public void ThrowAE() { throw new ArgumentException(); }
}

[Test]
public void ThrowETest()
{
    var t = new Thrower();
    Assert.That(() => t.ThrowAE(), Throws.Exception);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)