I'm playing around with a new "should" style of testing with a focus
on better error messages. Or error messages with context!
It's based on NUnit and RhinoMocks, so for comparison this is the
current Assert way:
Assert.That(contestant.Points, Is.EqualTo(1337));
For your troubles, you get this message, when it fails:
Expected 1337 but was 0
With Shouldly:
contestant.Points.ShouldBe(1337);
Which is just syntax, so far, but the message when it fails:
contestant.Points should be 1337 but was 0
It might be easy to underestimate how useful this is. Another example,
side by side:
Assert.That(map.IndexOfValue("boo"), Is.EqualTo(2)); // ->
Expected 2 but was 1
map.IndexOfValue("boo").ShouldBe(2); // ->
map.IndexOfValue("boo") should be 2 but was 1
Shouldly uses the source code at the ShouldBe statement to report on
errors, which makes diagnosing easier.
With RhinoMocks, it gives clearer messages about expectation
failures.
Here's the message without Shouldly:
Rhino.Mocks.Exceptions.ExpectationViolationException:
IContestant.PlayGame("Shouldly"); Expected #1, Actual #0
Shouldly's message:
Expected:
IContestant.PlayGame("Shouldly");
Recorded:
IContestant.PlayGame("Debugging");
IContestant.PlayGame("Logging");
IContestant.PlayGame("Drinking coffee");
IContestant.PlayGame("Commenting out test");
More at: http://snappyco.de/articles/2010-02-02-shouldly
Source at: http://github.com/snappycode/shouldly
Hit me up for any questions, feature requests or even better fork it!
It's cool...
but how come you aren't involved in helping us get this sort of
syntax into NUnit? *
Charlie
* which we are doing, but maybe it will be less cool without you!
> --
> You received this message because you are subscribed to the
> Google Groups "Seattle area Alt.Net" group.
> To post to this group, send email to altnet...@googlegroups.com.
> To unsubscribe from this group, send email to
> altnetseattl...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/altnetseattle?hl=en.
>
>
Sent: Monday, February 08, 2010 10:27 PM
To: altnet...@googlegroups.com
Subject: Re: Shouldly testing library
Sent: Monday, February 08, 2010 10:27 PM
To: altnet...@googlegroups.com
Subject: Re: Shouldly testing library
Sent: Tuesday, February 09, 2010 7:57 PM