Alex Rivera | Logout

TDD: Where to start the first test

Asked 2009-06-01T15:37:50.463
14

So I've done unit testing some, and have experience writing tests, but I have not fully embraced TDD as a design tool.

My current project is to re-work an existing system that generates serial numbers as part of the companies assembly process. I have an understanding of the current process and workflow due to looking at the existing system. I also have a list of new requirements and how they are going to modify the work flow.

I feel like I'm ready to start writing the program and I've decided to force myself to finally do TDD from the start to end.

But now I have no idea where to start. (I also wonder if I'm cheating the TDD process by already have an idea of the program flow for the user.)

The user flow is really serial and is just a series of steps. As an example, the first step would be:

  • user submits a manufacturing order number and receives a list of serializable part numbers of that orders bill of materials

The next step is started when the user selects one of the part numbers.

So I was thinking I can use this first step as a starting point. I know I want a piece of code that takes a manufacturing order number and returns a list of part numbers.

// This isn't what I'd want my code to end up looking like
// but it is the simplest statement of what I want
IList<string> partNumbers = GetPartNumbersForMfgOrder(string mfgOrder);

Reading Kent Becks example book he talks about picking small tests. This seems like a pretty big black box. Its going to require a mfg order repository and I have to crawl a product structure tree to find all applicable part numbers for this mfg order and I haven't even defined my domain model in code at all.

So on one hand that seems like a crappy start - a very general high level function. On the other hand, I feel like if I start at a lower level I'm really just guessing what I might need and that seems anti-TDD.

Edit
Report

1 Answer

1

I think you have a good start but don't quite see it that way. The test that is supposed to spawn more tests makes total sense to me as if you think about it, do you know what a Manufacturing Order number or a Part Number is yet? You have to build those possibly which leads to other tests but eventually you'll get down to the itty bitty tests I believe.

Here's a story that may require a bit of breaking down:

  • As a User I want to submit a manufacturing order number and receive a list of serializable part numbers of that orders bill of materials

I think the key is to break things down over and over again into tiny pieces that make it is to build the whole thing. That "Divide and conquer" technique is handy at times. ;)

answered 2009-06-01T15:44:39.433

Your Answer