What Is It?
Should Assertion Library (“Should” for short) is a library of test assertion methods for .NET. It is totally independent of, and completely compatible with any testing framework. It was created by Eric Hexter, and I subsequently added a fluent interface which I ported from ShouldIt. ShouldIt is now deprecated.
Should comes in two flavors:
- normal (Should.dll)
- fluent (Should.Fluent.dll).
Get It
You can get the latest binaries from NuPack or the project site.
By the way, if you haven’t tried NuPack yet, go get it right now! You’ve got it? Okay, open the Package Management Console and enter:
> Install-Package Should
or
> Install-Package ShouldFluent
This will install Should as a package in the current solution. You probably want to use either the fluent API or the normal API in any given test project – but not both. Choosing one or the other will promote a consistent practice within your team. Obviously, I prefer the fluent API.
Use It
There’s not much to say about usage. It’s really pretty intuitive and discoverable. Just start typing “.Should” after your actual object, and you will see what’s available. To give you a taste, here’s a simple example:
actual.ShouldNotBeNull();
actual.ShouldBeType<Foo>();
actual.ShouldBeSameAs(expected);
Or fluently:
actual
.Should().Not.Be.Null()
.Should().Be.OfType<Foo>()
.Should().Be.SameAs(expected);
There are several examples of both the normal and the fluent syntax here.
Enjoy!
A Note To ShouldIt Users: If you have been using ShouldIt, just remove the ShouldIt DLLs, add Should.Fluent.dll, and change the namespaces. Everything should just work. Of course depending on which test framework you were using with ShouldIt, the underlying assertion behavior could change slightly. It should be pretty easy to spot the differences and make any small corrections as needed.
[…] tuned for my next blog post: Getting Started With Should Assertion Library. Leave a […]
Pingback by Goodbye ShouldIt, Hello Should Assertion Library « Tim Scott's Blog — October 9, 2010 @ 7:23 pm
Thought you might want to know, I’m shipping the Should framework with NBehave alpha… http://sharpfellows.com/post/NBehave-alpha-now-shipping-with-Should-assertion-framework.aspx
Thanks for the great framework 🙂
Comment by Naeem Khedarun — October 28, 2010 @ 3:52 pm