Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no parameter for the fail message for Assert.NotNull in xUnit.net?

Tags:

c#

xunit.net

In constract to e.g. Assert.False where I can supply a message to be displayed when the assert fails, e.g. Assert.NotNull has only one overload that just takes the object to check. Is there a reason for it?

namespace Xunit
{
  public class Assert
  {
    // ...
    public static void False(bool condition, string userMessage);
    // ...
    public static void NotNull(object @object);
    // ...
  }
}
like image 569
David Avatar asked Apr 25 '17 19:04

David


People also ask

Which Assertion Method verifies that an Object is not null?

NotNull(Object, String, Object[]) Verifies that the object that is passed in is not equal to null If the object is null then an AssertionException is thrown.


1 Answers

Dogma. They believe that you should never have more than one assertion per test, thus you don't need it.

The solution, if you otherwise like xUnit, is to download the source code for just the Assert module and paste it into your project. It is separate from everything else specifically so that you can tailor it to your needs.


Here is my version of said library with messages added: https://github.com/docevaad/Chain/tree/master/Tortuga.Chain/xTests.Tortuga.Chain.SqlServer.source/shared/Asserts

like image 99
Jonathan Allen Avatar answered Nov 03 '22 16:11

Jonathan Allen