Getting the "unwashed" (aka "blue collar coders") to unit test

 

Roy Osherove has a great post on making TDD more accessible (which I would be remiss to mention that I am not really a part of the TDD movement except as a outsider/skeptic). There are a bunch of additional comments/posts in this regard which I won’t bore you with. You either got here because my post got linked to Roy’s thread or you are a regular reader here.

I was actually encouraged by Roy’s thoughts(again). He really gets it (I mean the reason why blue collar developers don’t do TDD). It’s all reminiscent of something I heard from within the security culture:

If it isn’t secure by default then... it isn’t really secure.

For instance, MVC was a web framework talked about by a bunch of people but no one REALLY used it until RAILS did it and made it easy to do (at least that’s my guess). In the ASP.NET space there have been alternative web frameworks (mostly MVC), but until MS did an MVC framework that was easy to use everyone used any web forms (you could have used an alternative ASP.NET Web Framework you know).

Improvements??

When I was at CodeBetter, I remember a lot of people complaining about how MS made it easy to develop crappy code using all kinds of ugly evil drag and drop mechanisms (DataSets and DataGrids come to mind).

As I look back on it, if that crew had decided let’s make it easier to build testable code by releasing a bunch of templates and making improvements to the testing frameworks (an add-in for VS that auto-creates class methods/properties while I’m writing test code would have been awesome). It could have even used mocking frameworks to determine what calls should be made in those properties/methods and add comments to that effect... This would make testing easier and would encourage test first.

You see there’s a way to get better code written, but it involves creating tools that make it easier to write good code (so "why would I want to write bad code... it’s easy to write good code"). I know for some of this won’t resonate. I fear that some love being "l33t" and so as long as coding is hard they feel like they are at the top of the food chain.

A Personal Experience

Chad Myers and I chatted a few weeks ago (or was it last week) in email about the testing I was doing. He really wanted me to post about my experience here. So, while I was being called out on my post where I was talking about SpDD, I was writing MbUnit code that looked like this:

   1: [RowTest("'A' Must Be False When Settings Object DisAllows 'A' For Customer")]
   2: [Row(true, 1, 2, 3, 4)]
   3: public void A_Must_Be_False_When_Settings_Object_DisAllows_A_For_Customer(
   4:                     bool expected, int parm1, int parm2, int parm3, int parm4)
   5: {
   6:     // Set up conditions
   7:     Assert.AreEqual(expected, SomeObj.SomeMethod(someSignature[]), "");
   8: }

I did this for something in my day job that absolutely had to be correct. Quality had to be 100%. The class under test had a bunch of rules (specs) that had to be tested. It had to be right... no questions asked, and having a regression suite of tests was an added benefit (it would never be wrong).

While I didn’t use classic DI, I was pretty close (so I could have mocked every dependency if I wanted to with minimal effort). Anyway, the net result was great. I have a set of regression tests and confidence that my understanding of the spec is covered with tests (so the end result should be a quality class that does what I would expect it to do).

Anyway, I’m really ashamed of one thing though. I’m afraid to admit that it took entirely too long IMNHO (Shawn C. don’t freak... it was a critical need): 1.5 days roughly.

Things like PEX may have helped a little, but the truth is I didn’t have time to learn a new tool (so I have no idea how quickly I could have done it with PEX)... I know, we never have the time. There are also tools out there for auto-gen’ing tests, but those aren’t that great either.

A Change

Something needs to change in this space for adoption to take off. Believe it or not I hope something does. The idea of a suite of regression tests sounds awesome to me... the idea that I have to write that test code isn’t quite so appealing... it either has to be easier to write tests or writing tests needs to help write code for me. At least that’s a suggestion.

As previously mentioned, I am not a TDDer. I’m a guy who gets some of these Alpha Geek ideas, but I’m more a "Beta Geek." I have one foot in the blue collar developer corner and one foot slightly over the line toward cutting edge developer... I try to walk the line and find better ways of doing things which is why TDD has me somewhat hung up (I like tests and the net result... but I don’t like the effort involved). I know TDD is about something else as well... but for me the benefit is the regression suite... all other things are simply window dressing appealing to an unknown "best practices" authority.

[That’s another rant in and of itself... the whole "best practices" thing.... who’s defining this? You guys sometimes need to do a better job with that... quoting "best practices" is like saying "it’s better because I said so." At least that’s what most of us hear... if you are going to use it then quote your authority.... at least if you say "Fowler said" then I can determine if "Fowler" is an authority I respect, and whether he carries weight with me].

Print | posted on Tuesday, September 23, 2008 4:05 PM

Feedback

# re: Getting the "unwashed" (aka "blue collar coders") to unit test

left by Cory Foy at 9/23/2008 9:41 PM Gravatar
Jay,

Perhaps we should sit down and do some TDD. Michael Russo (the guy who runs Agile Tampa) and I are going to be doing a TDD session in November at Agile Tampa, and again at the Tampa Code Camp in December. I'd be more than happy to sit down and at least give TDD a go with you if you'd like.

Cory

# re: Getting the "unwashed" (aka "blue collar coders") to unit test

left by Jay Kimble at 9/23/2008 11:43 PM Gravatar
We can try to do that... I've tried it, and it wouldn't hurt to try it again.

it's just not easy to do...

Jay

# re: Getting the "unwashed" (aka "blue collar coders") to unit test

left by Benjy at 10/6/2008 6:43 AM Gravatar
Jay,
Interesting post. Whats your opinion on tools that auto-generate tests? VS has some features like that for webservices etc. That would take some of the burden of writing tests away wouldnt it? TDD purists may not like it, and with my understanding and usage (to some extent) of TDD so far, it does help in ensuring you write only the necessary code, but as you point out, sometimes its a pain.And theres also the issue of inheriting an existing code base that has little or no tests, so theres not much option except to write them after the fact in which case auto-generation could be a life-saver.

# re: Getting the "unwashed" (aka "blue collar coders") to unit test

left by Jay Kimble at 10/6/2008 8:34 AM Gravatar
Benjy,

I would love to be able to auto-generate tests if it was "intelligent." I mean I want tests that actually test the system. PEX is interesting, but it needs to go further.

I need to experiment with that feature of VS (webservices testing).

I could outline a few more ideas I have, but they will fall on deaf ears I suspect... or worse be flamed for misleading people.

Jay

# re: Getting the "unwashed" (aka "blue collar coders") to unit test

left by Shawn at 10/6/2008 6:10 PM Gravatar
Jay - you have my word, I will NEVER freek over too much testing! Cross my heart, hope to...

Later man.
S
Title  
Name
Email (never displayed)
Url
Comments   
Please add 8 and 1 and type the answer here: