Ctrl + Alt + E

The Joy of Good Test Driven Development

I came up to a problem on my current project that was tough to think about how to tackle.  Fine, I whipped up a test, went through the usual steps, write a test, see it fail, write enough code to get the test to pass, refactor, repeat.  When I tested for code coverage, I was pleased at my 100%; yep, 100% of the code I just wrote had tests that excercised all lines.  Woo Hoo! The project has grown quite a bit, so I decided to run all of the tests in my solution...

The Pain of Bad Test Driven Development

When I ran all of the tests in my solution, most of them broke.

One reason is that I have a testfixture named "SchemaTests" and it has one test method named "CreateSchema". I'm using ActiveRecord for my persistence layer, and it has a cool method I use, ActiveRecordStarter.CreateSchema, when I'm prototyping something.  Essentially it allows you to write your C# objects first, and figure out how they need to save their stuff second, you end up with a better data model to support your solution, but that's another story in and of itself.(and yes, I ended up recreating the schema and losing anything I had saved to the database) 

Back the problem.

Other tests that broke were ones I had whipped up quickly to excercise(I'm ashamed to admit) external web services :(

BAD DEVELOPER BAD BAD DEVELOPER...

The database tests needed to be somewhere else, once the schema was done on that portion, there really wasn't a need to run any of the tests, it's just saving stuff and that's what ActiveRecord does for you.  The dependency on  external services in my tests was me being lazy(and that's lazy in the bad way).

Now What

I yanked every test that interacted with an external resource. Sadly, that also removed a ton of coverage. I had gone down the path of fixing the tests that broke, but upon looking at what they did, I realized they weren't very good to begin with, most likely not written with Test Driven Development in mind. My report card is not looking good on this so far.

Luckily, the code is pretty well factored, so I'm able to mock all of the external services with RhinoMocks.  I have some more tests to write (which always sucks after the fact) but that's my punishment.

 
Author: , 0000-00-00