Tuesday, July 14, 2009

The art of Unit Testing with Examples in .NET

I recently bought a copy of The Art of Unit Testing: with Examples in .NET by Roy Osherove, taking advantage of a discount being offered by Manning.

Already owning xUnit Test Patterns: Refactoring Test Code (Addison-Wesley Signature Series) by Gerard Meszaros and Working Effectively with Legacy Code (Robert C. Martin Series) by Michael Feathers, I was interested to see what new insights Osherove would bring, especially as he would be focussing purely on the .NET platform (code samples are in C#).

The book is divided into 4 sections.

Part 1 (which I skimmed through) was an introduction to unit testing. Osherove uses NUnit for his examples which is reasonable considering it is probably the most popular unit testing framework for .NET at the moment.

His preferred naming convention for test methods is interesting – "[MethodUnderTest]_[Scenario]_[ExpectedBehaviour]". It contrasts with the "natural sentence" style I currently favour (which I'd trace back to Jean-Paul Boodhoo's unit testing episodes on dnrTV).

He also recommends naming test classes with a "Tests" suffix. I've always used the singular "Test", but I take his point that each test class does contain multiple tests so plural may be more accurate.

Part 2 introduces stubs, mock objects and isolation frameworks (aka mock object frameworks). Following a poll held on Osherove's blog, Rhino Mocks was chosen to demonstrate how a framework can simplify creating mock objects. I could be wrong, but you almost get a sense that this was done somewhat grudgingly considering Osherove himself works for TypeMock (who sell a commercial mocking framework). Curiously whilst including a link to the Rhino Mocks download site, he doesn't even mention Ayende's name at all.

Osherove makes the following recommendations about stubs and mocks:

  • Use nonstrict mocks when you can
  • Use stubs instead of mocks when you can
  • Avoid using stubs as mocks

I found this interesting, as we've been writing a lot of unit tests lately, and one of the things we're coming to realise is that brittle tests can be annoying. Tests that still test your code, but are more flexible about exactly how the code under test works (rather than setting strict expectations for each and every method call) are going to be more useful and less effort to maintain.

Part 3 looks at various strategies for organising tests and a number of patterns and anti-patterns to follow when creating tests.

Part 4 covers how to make unit testing the norm in an organisation, and how to work with legacy code.

Having some experience writing unit tests, I did find this book a bit light on. Osherove references Meszaros and Feather's books regularly. I would also consider both of these works cover the topic in a more detailed and thorough manner. However they are probably not necessarily as good a starting point for someone new to unit testing, especially someone who's main experience lies in developing for the .NET platform.

I finished the book surprisingly quickly – pleased that I'd learned a few new things, but left feeling that it would have been nice to learn a few more.

Wednesday, July 01, 2009

Firefox 3.5

Today is "Upgrade to Firefox 3.5" day :-)

My upgrade went very smoothly, and one nice feature was it warned me beforehand which extensions wouldn't work with the new version.

Post-upgrade, it found a compatible version of Firebug, but I'm still waiting for updates of

  • Bookmark Duplicate Detector
  • Google Notebook
  • Live Writerfox
  • Microsoft .NET Framework Assistant 1.0

The following extensions work ok:

  • DownThemAll
  • English (Australian) Dictionary
  • IE Tab
  • Xmarks

They reckon 3.5 is about twice as fast as 3.0. It certainly does seem snappier.

As a side note, I just noticed that Google Notebook is no longer being developed. Might be time to finally make the transition to Evernote.

Saturday, June 27, 2009

Saasu

(or two things I remember from this month's SQL Server user group meeting)

This month, Rob presented on "SQL in the cloud". It was an interesting talk, if nothing else for the interesting direction(s) that Microsoft have taken trying to get this whole "cloud database" concept up and running.

Rob's joke turned out to be quite good (considering the context of a SQL Server User Group - "A man walks into a bar, sees two TABLEs and says 'Can I JOIN you?"

The other thing which he mentioned as part of a discussion on cloud computing was Saasu – an online accounting site. Think MYOB or Quicken but entirely online. This attracted my interest as I've been using MYOB Business Basics to track Narelle's scrapbooking business for a few years, and I've come to discover that particular product isn't really suited to a reseller type business.

Saasu is free to join and if you keep below 15 transactions a month it is free to use. Following the familiar service model, once you start using it more often than that you need to pay a small amount each month. That cost would probably be less than having to buy an upgrade for MYOB each year, so it is quite competitive. Even though it's a global site, they have facilities for handling Australian accounting and tax requirements (eg. GST and BAS).

So far, I'm quite impressed, especially considering they support handling inventory (something Business Basics couldn't even do).

Monday, June 22, 2009

Tracing and logging WPF

Whilst researching unit testing WPF applications I came across Bob King's answer to this question on StackOverflow.

WPF DataBinding can appear to be a bit of a mysterious black box, but I now know that you can enable diagnostic trace sources to see what's happening under the covers. Mike Hillberg shows some examples in this post.

Saturday, June 20, 2009

42% discount from Manning

I saw today on Jeffery Palermo's blog that Manning are offering a limited time discount on "Alt.Net" books if you use the discount code "alt42" before June 25th. I've taken up the offer and ordered the following:

Some good reading, and just in time to claim for a tax deduction too.

Wednesday, June 17, 2009

Error message of the day – "Something has went wrong"

And I think I was probably the one who was responsible – a bit said for someone who normally does take the time to correct grammar and spelling errors :-)

Thankfully not something end-users get to see, but it does seem quite appropriate for an error (in an ironic kind of way).

Sunday, June 14, 2009

David and Fiona Meier

It’s not every day that your sister gets married, but it was yesterday!

My sister Fiona married her fiancé David Meier at The Corner Uniting Church.

The service was lovely and it was great to see lot of family and friends there. Following an afternoon tea at the church, we joined the bridal party for photos, then after leaving the kids with a babysitter headed off to the reception at Belair Park Country Club (situated in the grounds of Belair National Park).

The reception was very enjoyable, with musical entertainment provided by Heidy De Ruyter. Some really good speeches were given by the best man, bridesmaids and both fathers of the groom and bride.

My mum (the mother of the bride) came out of retirement to make possibly her last wedding cake, and she did a fantastic job.

Sometime you hear of weddings that don’t go to plan, have awkward moments or end up with the bride (and others) distressed and embarrassed. Maybe you’ve even attended one? I’m pleased to report that yesterday it was nothing like that! Everyone (especially the bride and groom) had a great time, enjoyed themselves immensely and went home knowing that David and Fiona are going to be very happy together.

Fiona and David chose Meg Hansen as their professional photographer (I took the ones you see here!) and Pete Dobré as videographer (who when he’s not videoing wedding can be found taking spectacular photos of Australian landscapes)