I'm currently rewriting some unit tests to use NUnit 3 instead of NUnit 2 and need to change some asserts to contraint-based asserts. I have the following asserts:
Assert.IsNullOrEmpty(result);
That I've changed to:
Assert.That(result, Is.Null.Or.Empty);
However, I'm not totally pleased with the readability when asserting IsNotNullOrEmpty
:
Assert.That(result, Is.Not.Null.And.Not.Empty);
My current suggestion is to create the following static class:
public static class Text
{
public static EmptyConstraint IsNullOrEmpty => Is.Null.Or.Empty;
public static EmptyConstraint IsNotNullOrEmpty => Is.Not.Null.And.Not.Empty;
}
Usage:
Assert.That(result, Text.IsNotNullOrEmpty);
This offers better readability at the expense of introducing a custom constraint. Is there a standard way of making the same assertion, or should I continue using Is.Not.Null.And.Not.Empty
instead?