Improving the Assert class to include messages and additional methods

Nov 11, 2012 at 3:06 AM

Hello,

When writing functional tests using xunit, I find myself confused as to what went wrong because messages aren't really useful. I'd like to extend the Assert class so that its methods would accept user message. In essence, it just means that a method like NotNull would be overloaded so its looks as follows:

public static void NotNull(object @object, string format, params object args)
{
    if (@object == null)
        throw new NotNullException(string.Format(format, args));
}
	
public static void NotNull(object @object)
{
    if (@object == null)
        throw new NotNullException();
}

What is the process to contribute to this project, if any?

Werner

Nov 14, 2012 at 1:30 AM
Edited Nov 14, 2012 at 1:33 AM

Good idea to ask here before blindly logging an issue, IMO...

From the summary page:

 

chaliy Sep 8, 2008 at 12:06 PM 
Guys, could you please explain reasons why you remove(not implemented) message for assertion methods?

 

BradWilson Sep 8, 2008 at 4:12 PM 

@chilay, the reason we removed messages from everything except True/False is because the asserts should be descriptive enough. Assert.Equal(42, someValue, "someValue should've been 42") doesn't add a lot of value, and if you can't tell what an assert is testing when you write it, then it's probably broken anyway. Worst case, you can add a comment to the assert method. We left the messages on True/False, because these tend to be the catchall handlers used when a specific assertion is not present.

(the thread continues for a bit too)

From sustained usage, I agree too.

Re contributing...

If you search around you'll find that we're in the midst of a transitioning process from MS copyright and MS-only contributions to Brad and Jim both not even fulfilling that criteria. That, combined with the move to git(not hub) should mean pull requests being accepted sooner or later (but I know nothing and no timelines should be inferred).

See the what's new in 2.0 discussion post for info regarding the main direction of current development.

And go upvote any of my assertion extensions issues now!

EDIT: BTW most people that dont want to confine themselves to the OOTB suite of Assertions use stuff like Shouldly and the 30ish NuGet packages of that ilk which provide various elegant/overkill ways of providing matchers / composibility mechanisms and e.g. ways of rendering the expressions involved in the message of AssertionException

Nov 14, 2012 at 6:12 PM
Edited Nov 14, 2012 at 6:13 PM

Its unfortunate. When writing functional tests, those messages produced by assertions are not that useful. Numerous assert statements produce similar messages.  It requires access to source and the line where the assert failed.  Not only is it unproductive, but limits the use of the tests outside of development.

Coordinator
Nov 14, 2012 at 8:24 PM
You can write your own assertions. There's no need to wait for us.