I'm a great believer in making your unit tests as easy to read and understand as possible. I was thinking about how I could improve my tests the other day and thought about using extension methods to create a more fluent way of creating complex assertions.
This has allowed me to create a complex assertion like:
Which I hope you'll agree reads a lot easier than those three assumptions on separate lines. Also, note that I have added the ability to use a predicate for when there isn't a method which quite matches your needs.
Here's the code for the extension methods:
And here are the tests for the extension methods:
I'd love to hear some feedback on what you think of this style.
This entry was posted on at Tuesday, January 29, 2008 and is filed under Extension methods, MbUnit, Unit testing. You can follow any responses to this entry through the RSS 2.0. You can leave a response.