Spectacle

    No comments

    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.

    No, this isn’t some witty post tying some obscure Seinfeld episode to my daily life.  Nor is it some great philosophy gleaned from the musings of latex salesman, puffy shirts or Keith Hernandez.

    Although, now that I think about it, I should probably look into those.

    This post is about a simple technique I read about on lifehacker.  A fellow once asked Jerry Seinfeld how to become a better comedian.  He replied that the way to be a better comedian was to write better jokes.  The way to write better jokes was to write every day.

    Jokes aside (huh huh), that’s good advice for doing anything.

    That’s easy, you say.  Just do more of what you want to be doing.  I’ve said similar things myself.  Do ‘x’ more and more and you’ll become better at ‘x’.  And here I sit with a blog that started October something or other and it’s taken this long to get out a second  post.

    The key to Seinfeld’s technique was how he motivated himself to write everyday.

    First, get a big wall calendar that has the whole year on one page and hang it on a wall.  Second, get a red magic marker.  Everyday you write (or do ‘x’), put a big X on the day.  Write (or do ‘x’) for a couple of days in a row and you’ll have a chain.  Keep going and the chain gets longer and longer.  Pretty soon, you’ll need to keep it going.

    It sounds simple because it is.

    Everything I’m good at, I am because of consistent practice.  Math science, artistic ventures, whatever,  they all take commitment and practice.  It’s easy to skip a few days here and there when there is no visible reminder of what you should be doing.  Those days might turn into weeks or months or heaven forbid, never.

    So why should blogging, or anything really, be any different?

    I know what I’m looking for this holiday season, I just hope I get that red marker with a compass in the stock, and this thing which tells time.

    Hello World

    1 comment

    I recently stumbled upon one of Steve Yegge older posts about why you should write blogs.  I always meant to setup a blog, but never got around to it.  He pretty much hit every reason why I had procrastinated setting this up.  So, now it’s done.  Here’s to hoping I stick with it.