我想在断言失败时提供一条消息,但我想不出办法。
[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);
}
答案 0 :(得分:2)
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void EmptyNameInConstructorThrowsExceptionTest()
{
SomeClass someClass = new SomeClass(null);
Assert.Fail("Exception not thrown");
}