You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Markus Weimer <ma...@weimo.de> on 2016/01/19 20:13:13 UTC

xUnit error messages?

Hi,

while reviewing REEF-1133, I realized that xUnit's `Assert` doesn't take
a string parameter with the error message for when the assert fails. I
quite like that feature in JUnit as it makes for easier to parse test
failures. Does anyone know whether there is an equivalent in xUnit?

Thanks,

Markus

Re: xUnit error messages?

Posted by Anupam <an...@gmail.com>.
> Or is it "just"
> the effort of writing, maintaining and using those Asserts?

Yes. No tooling change, as xUnit already makes their Assert class
partial and available as source via NuGet.


On 21 January 2016 at 12:49, Markus Weimer <ma...@weimo.de> wrote:
> On 2016-01-19 15:26, Anupam wrote:
>> Take a look at this: https://github.com/xunit/xunit/issues/350 ; Nice
>> discussion on why xUnit did not add the string message.
>
> Interesting choice. I tend to agree that tests *should* be
> self-explanatory. But not everyone who runs our tests also reads their
> code. Hence, having some error message that they can understand seems
> useful to me.
>
>> Personally I do not like using Assert.True instead of Assert.Equal.
>> We should instead create our own assertion for equals with message?
>
> What would we loose in this approach? Tooling support? Or is it "just"
> the effort of writing, maintaining and using those Asserts?
>
> Markus



-- 
Anupam
Bellevue, WA
Ph: +1 (425)-777-5570

Re: xUnit error messages?

Posted by Markus Weimer <ma...@weimo.de>.
On 2016-01-19 15:26, Anupam wrote:
> Take a look at this: https://github.com/xunit/xunit/issues/350 ; Nice
> discussion on why xUnit did not add the string message.

Interesting choice. I tend to agree that tests *should* be
self-explanatory. But not everyone who runs our tests also reads their
code. Hence, having some error message that they can understand seems
useful to me.

> Personally I do not like using Assert.True instead of Assert.Equal.
> We should instead create our own assertion for equals with message?

What would we loose in this approach? Tooling support? Or is it "just"
the effort of writing, maintaining and using those Asserts?

Markus

Re: xUnit error messages?

Posted by Anupam <an...@gmail.com>.
Take a look at this: https://github.com/xunit/xunit/issues/350 ; Nice
discussion on why xUnit did not add the string message.
Quoting from the link:
"*We obsolesced most of the Assert methods which take user messages.* The
only ones we left are those on Assert.True and Assert.False, which tend to
be catch-all asserts which might require documentation. We will be removing
the obsolesced methods in 1.0 RTM, so please move your calls to the
message-less variants.

I could not find a blog post that talked about "why", even though we've
mentioned it several times. I'm just not sure it every got a permalink.

We are a believer in self-documenting code; that includes your assertions.
If you cannot read the assertion and understand what you're asserting and
why, then the code needs to be made clearer. Assertions with messages are
like giving up on clear code in favor of comments, and with all the
requisite danger: if you change the assert but not the message, then it
leads you astray.

To support people writing better assertions, v2 includes a NuGet package
that ships the assertion library in source code. The Assert class is a
partial, so you can add whatever assertions you like to the built-in set.
We've even gone so far as to publish gists with extra assertions, just to
show people how it's done:https://gist.github.com/bradwilson/7797444"


Personally I do not like using Assert.True instead of Assert.Equal.
We should instead create our own assertion for equals with message?

I don't feel strongly about this though. After so many +1s, I guess people
have already made a decision, just putting my point out there.


On 19 January 2016 at 14:02, Byung-Gon Chun <bg...@gmail.com> wrote:

> +1
>
> -Gon
>
> 2016. 1. 20. 오전 6:13 Dongjoon Hyun <do...@apache.org> 작성:
>
> > +1.
> >
> > Dongjoon
> >
> >> On Tue, Jan 19, 2016 at 1:01 PM, Andrew Chung <af...@gmail.com>
> wrote:
> >>
> >> I am +1 for it.
> >>
> >> Thanks,
> >> Andrew
> >>
> >>> On Tue, Jan 19, 2016 at 11:21 AM, Markus Weimer <ma...@weimo.de>
> wrote:
> >>>
> >>>> On 2016-01-19 11:17, Mariia Mykhailova wrote:
> >>>> Some xUnit methods take error message, for example, Assert.True
> >>>> Maybe we should use that instead of Assert.Equal when we want specific
> >>> message.
> >>>
> >>> Ah, that sounds good. What do others think: Should we make this part of
> >>> our coding style?
> >>>
> >>> Markus
> >>
>



-- 
Anupam
Bellevue, WA
Ph: +1 (425)-777-5570

Re: xUnit error messages?

Posted by Byung-Gon Chun <bg...@gmail.com>.
+1

-Gon

2016. 1. 20. 오전 6:13 Dongjoon Hyun <do...@apache.org> 작성:

> +1.
> 
> Dongjoon
> 
>> On Tue, Jan 19, 2016 at 1:01 PM, Andrew Chung <af...@gmail.com> wrote:
>> 
>> I am +1 for it.
>> 
>> Thanks,
>> Andrew
>> 
>>> On Tue, Jan 19, 2016 at 11:21 AM, Markus Weimer <ma...@weimo.de> wrote:
>>> 
>>>> On 2016-01-19 11:17, Mariia Mykhailova wrote:
>>>> Some xUnit methods take error message, for example, Assert.True
>>>> Maybe we should use that instead of Assert.Equal when we want specific
>>> message.
>>> 
>>> Ah, that sounds good. What do others think: Should we make this part of
>>> our coding style?
>>> 
>>> Markus
>> 

Re: xUnit error messages?

Posted by Dongjoon Hyun <do...@apache.org>.
+1.

Dongjoon

On Tue, Jan 19, 2016 at 1:01 PM, Andrew Chung <af...@gmail.com> wrote:

> I am +1 for it.
>
> Thanks,
> Andrew
>
> On Tue, Jan 19, 2016 at 11:21 AM, Markus Weimer <ma...@weimo.de> wrote:
>
> > On 2016-01-19 11:17, Mariia Mykhailova wrote:
> > > Some xUnit methods take error message, for example, Assert.True
> > > Maybe we should use that instead of Assert.Equal when we want specific
> > message.
> >
> > Ah, that sounds good. What do others think: Should we make this part of
> > our coding style?
> >
> > Markus
> >
> >
>

Re: xUnit error messages?

Posted by Andrew Chung <af...@gmail.com>.
I am +1 for it.

Thanks,
Andrew

On Tue, Jan 19, 2016 at 11:21 AM, Markus Weimer <ma...@weimo.de> wrote:

> On 2016-01-19 11:17, Mariia Mykhailova wrote:
> > Some xUnit methods take error message, for example, Assert.True
> > Maybe we should use that instead of Assert.Equal when we want specific
> message.
>
> Ah, that sounds good. What do others think: Should we make this part of
> our coding style?
>
> Markus
>
>

Re: xUnit error messages?

Posted by Markus Weimer <ma...@weimo.de>.
On 2016-01-19 11:17, Mariia Mykhailova wrote:
> Some xUnit methods take error message, for example, Assert.True
> Maybe we should use that instead of Assert.Equal when we want specific message.

Ah, that sounds good. What do others think: Should we make this part of
our coding style?

Markus


RE: xUnit error messages?

Posted by Mariia Mykhailova <ma...@microsoft.com>.
Some xUnit methods take error message, for example, Assert.True
Maybe we should use that instead of Assert.Equal when we want specific message.

-Mariia

-----Original Message-----
From: Markus Weimer [mailto:markus@weimo.de] 
Sent: Tuesday, January 19, 2016 11:13 AM
To: dev@reef.apache.org
Subject: xUnit error messages?

Hi,

while reviewing REEF-1133, I realized that xUnit's `Assert` doesn't take a string parameter with the error message for when the assert fails. I quite like that feature in JUnit as it makes for easier to parse test failures. Does anyone know whether there is an equivalent in xUnit?

Thanks,

Markus