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).
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)
6: // Set up conditions
7: Assert.AreEqual(expected, SomeObj.SomeMethod(someSignature), "");
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.
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].
| posted on Tuesday, September 23, 2008 4:05 PM