I’ve don’t like writing unit tests, plain and simple. Do I write test code? Absolutely. I think not writing tests will set you up for a truckload of fail.
What I don’t like about writing the tests is the seemingly foreign language that their written in. Sure it might be C# or VB, but it looks drastically different from the object oriented code we write on a daily basis.
1: MyClass superGuy = new MyClass();
2: string result = superGuy.GetResult();
3:
4: Assert.AreEqual("good result", result);
I just don’t think that way. For one, I can’t just look at that line and know what’s being tested without having to read through the entire line, Two, it takes me a few seconds to mentally adjust to thinking about the code that way. Finally, I have a tendency to swap the expected and actual when writing out the asserts which confuses me when the assertion fails.
Wouldn’t it be nice to be able to write:
1: MyClass superGuy = new MyClass();
2: string result = superGuy.GetResult();
3:
4: result.IsNotNull();
5: result.IsEqualTo("good result");
6: // or combine them
7: result.IsNotNull().And.IsEqualTo("good result");
That’s what spectacle is all about. It’s a collection of extension methods to ease the pain when writing unit tests. It only targets MbUnit v2 right now, because that’s what I’m currently using.
If you want to try it out, clone it from the github repository and build it. Next all you’ll need to do is add a reference to your test project and add a “using Spectacle.MbUnitAssertions;” to your code files.