Unit test ignore and provide explanation about it

Viewed 949

Is it possible to provide an explicative message in the Ignore decorator to a unit test in C#, like this?

[TestMethod]
[Ignore("This is intended to work locally only because lack of permissions")]
public void TestStartAcquireIfEmpty()
{

}

So that in case a future development is done, this decorator can be removed from the unit test

2 Answers

You could add this line as the first line of your test:

Assert.Inconclusive("This is intended to work locally only because lack of permissions");

The test result will be shown as inconclusive with this message.

Three of the most popular .NET test frameworks allow to mark test as ignored and provide ignore reason:

  • MsTest's IgnoreAttribute has constructor accepting message parameter
  • Similarly NUnit's IgnoreAttribute has constructor accepting reason parameter
  • XUnit requires to fill Skip property (which is of string type) to ignore test
Related