是否有方法提供带有ExpectedException属性的失败消息?

本文关键字:属性 失败 消息 ExpectedException 有方法 是否 | 更新日期: 2023-09-27 18:04:26

我想在断言失败时提供一条消息,但我不知道如何做到这一点。

[Test]
public void CreateInstanceTest()
{
    SomeClass someClass = new SomeClass();
    Assert.IsNotNull(someClass, "Constructor could not return an instance");
    //provide failure message here
}

我在这个测试中怎么做?

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void EmptyNameInConstructorThrowsExceptionTest()
{
    SomeClass someClass = new SomeClass(null);
}

是否有方法提供带有ExpectedException属性的失败消息?

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void EmptyNameInConstructorThrowsExceptionTest()
{
    SomeClass someClass = new SomeClass(null);
    Assert.Fail("Exception not thrown");
}
相关文章: