1

I want to provide a message when assertion has failed but I can't figure out a way to do it.

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

How do I do it in this test?

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void EmptyNameInConstructorThrowsExceptionTest()
{
    SomeClass someClass = new SomeClass(null);
}
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156

1 Answers1

2
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void EmptyNameInConstructorThrowsExceptionTest()
{
    SomeClass someClass = new SomeClass(null);
    Assert.Fail("Exception not thrown");
}
Zruty
  • 8,377
  • 1
  • 25
  • 31