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:
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.
As a side note... is this how you'd use stories?
As an assembler I want to get a list of part numbers on a mfg order So that I can pick which one to serialize
To be truthful, an assembler would never say that. All an assembler wants is to finish the operation on mfg order:
As an assembler I want to mark parts with a serial number So that I can finish the operation on the mfg order
Red, Green and Refactor is the three phase of Test Driven Development and this the sequence that get followed while writing code. When followed, this order of steps helps ensure that you have tests for the code you are writing and you are writing only the code that you have to test for.
TDD is a software-driven process that includes test-first development. It means that the developer first writes a fully automated test case before writing the production code to fulfill that test and refactoring. It is a practice of writing a (failing) test before writing the code of a feature.
Here's how I would start. Lets suppose you have absolutely no code for this application.
Assert.AreSame(3, controller.RetrieveParts(mfgOrder).Count)
return new List<MfgOrder>{new MfgOrder(), new MfgOrder(), new MfgOrder()};
You'll also need to implement classes for MfgOrder, for example.The main point here is separating the application in very small parts, and testing those small parts individually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With