« Please Find Posted This Blog Entry | Main | Ignored test are OK; too many ignored tests too long are a smell »

November 07, 2006

Time to go home? Leave a broken test

I often have to take a few minutes at the beginning of each day to remember where I left off yesterday. I've tried things like leaving a note to myself to remind me of the details of my work in progress.

The most effective thing I've found, though, is leaving a broken test.

It's simple and effective if you're test-driving code. For example, let's say I'm writing a class that encapsulates whether a password meets a password policy. I'm hungry, tired and want to go home in time to go for a run:

[Test]
public void ValidPasswordMustHaveANumber()
{
    Password password = new Password( "PasswordWithNoNumber" );

Assert.IsFalse( validator.IsValid( password ), "passwords without a number are invalid" );
}

When I come in the next morning I'll run the tests and see:
Assertion failed: passwords without a number are invalid.

Then I'll remember where I left the previous day.

Posted by gsmith at November 7, 2006 07:50 AM

Comments

IMHO, this is not a good idea. The idea behind TDD and CI is that all tests pass 100% all the time.

Why don't you just put a post-it note next to your keyboard with the name of the TestCase you need to keep on working tomorrow?

Posted by: No no no at November 7, 2006 01:14 PM

To no no no:

It doesn't mean you have to check it in and break the build. Sometimes I think it's okay to have a part of the build where you can check in 'in progress' tests - but obviously should be very small.

Posted by: Pat at November 7, 2006 02:15 PM

I like to do the same thing, usually with an Assert.Fail("Come back here"). In the spirit of TDD, it's a TODO that bites back.

Posted by: Jeremy Miller at November 7, 2006 03:27 PM

I think this idea was in fact formulated long time ago by Kent Back ;-).

./alex
--
.w( the_mindstorm )p.

Posted by: Alex Popescu at November 9, 2006 03:34 PM

This is funny. I am involved in an open-source exercise, where some people get together for an hour and half once a week to write some code.

In this context, trying to remember where we left it the last time is a much bigger problem than usual. And we solve it the same way as you suggest: leaving a broken unit test.

Posted by: Alexey Verkhovsky at November 9, 2006 08:00 PM