11.26.08

Test-Infected: Revisited

Posted in Agile, Journal, Software Development, TDD at 6:04 am by Pablosan

There is a marked shift in the way a developer approaches their craft once they become test-infected. Instead of tests being an afterthought, if thought of at all, they become the starting point. Consistently… as in, always.

Here is how to tell when a developer has become test-infected:

  • When researching a bug/issue, they first look for Unit Tests to guide them through the production code to the source of the problem
  • When looking at code for the first time, they first look for Unit Tests to inform them as to how the code should function
  • In the first two situations, if no tests exist, they write them
  • In the first two situations, if tests exist but are not clear, they refactor them
  • When unsure of the approach needed to add a feature or fix a bug, they first write tests to help them discover a good solution
  • Once a bug has been tracked down and they know what they need to do to fix it, they first write a test that fails because the bug is there, fix the bug, and then run the test again to see it pass
  • When they are faced with the need to refactor, they avoid changing production code until they are satisfied that test coverage will insure their success
  • When asked by a colleague to take a look at code they’ve been working on, their first comment is “show me your tests”
  • Their mindset toward testing shifts from “This cannot be tested” to “How might this be tested?”

All of this can be reduced to two, simple questions:

  • Where are the tests? and
  • What do they say?

So how are you doing? Is this the approach you find yourself taking? Do you find yourself looking for solutions or looking for excuses?

11.24.08

TDD & DI

Posted in Journal, Software Development, TDD at 9:25 am by Pablosan

I make it a point to ask for feedback continually from my TDD course attenders. When I get to the point in the course where we look at dealing with dependencies and introduce Test Doubles along with the requisite Java Interfaces and, eventually, factories, a couple questions frequently arise: why don’t we just use Dependency Injection? Isn’t DI considered the current OO wisdom when it comes to dealing with dependencies? The second question is easier to answer than the first: “Yes, DI is strongly encouraged” (though it wasn’t always… at least not by this particular developer, as Craig Walls well knows… but that’s a story for another day). So, again, why isn’t it in the  course material?

There are at least two reasons. Let me start with the weakest. The course I’m teaching was intentionally designed to limit tool dependencies to a fairly current version of Java (usually 1.5) and JUnit (usually 4.x). There is a good reason for this: simply put, it keeps the course generic. Any time I’ve tried to branch out from these two technologies I’ve ended up in a quandary because, by making a specific technology choice, it would either become irrelevant to too many people or the material would become too complex to fit in the time constraints of a classroom.

The second reason is more about why the “old-fashioned”, manual approach is still taught: even when using tools to improve consistency in solving certain, recurring problems (i.e. DI Frameworks), the developer should understand, at least to some extent, how the tool is solving the problem. An axiom of sorts that I strongly advocate is “Choose the right tools to handle the mundane, but don’t use them blindly.”

These same questions about DI came up in my latest class, taught last week here in the UK. For some reason, though, this time it struck me differently (maybe it was the “accent” <evil grin>). As the discussion progressed, I realized that I am already teaching all of the pieces that go into DI: all I need to do is put all the pieces together in one example.

I think it’s past time for me to go at least one step further than implementing a factory and, at the very least, implement DI manually. And I already have the example completed! With any luck, you’ll be able to see for yourself over on CodeNotes in the next several days. I’ve also completed a refactoring, moving from a manual approach to using Guice. Sorry, Craig. It’s not Spring… at least not yet.

11.18.08

Feeling a Bit Skittish

Posted in Journal, TDD, Travel at 5:50 pm by Pablosan

My stay in London is off to a very good start. I just finished teaching my first TDD class, which was very enjoyable thanks to a couple of skeptics asking great questions and considering everything presented carefully. The discussion was lively and sometimes out of my control, which is just how I like it.

So why the title?

Exhibit A:

The flat near MI-6

The flat near MI-6 (click image for full-size version)

Yes, that really is MI-6 and, yes, that really is the flat I’m staying in. Further, upon looking out the window of the conference room where I held my training, I noticed a certain, rotating sign. Sheesh! I guess I need to be on my best behavior… oops! I mean, behaviour!