When using TDD, what heuristic do you use to choose which test to write next?

The first part of the TDD cycle is choosing a test for failure. I would like to start a community wiki about this selection process.

Sometimes the choice of dough to start with is obvious, start with low hanging fruit. For example, when writing a parser, a simple test to start with is one that does not process input:

def testEmptyInput(): result = parser.parse("") assertNullResult(result) 

Some tests are easy to pass, requiring a small implementation code, as in the example above.

Other tests require passing complex slabs of implementation code, and I have the feeling that I did not do the β€œeasiest thing to pass the test”. At this point, I stop trying to pass this test and select a new test to try to pass, in the hope that it will show an easier implementation for the problematic implementation.

I would like to examine some of the characteristics of these simple and complex tests, how they affect the selection and organization of test documents.

How does test selection relate to top-down and bottom-up strategies? Can anyone recommend entries that examine these strategies for TDD?

+4
source share
2 answers

I start by fixing the most valuable code behavior.

For example, if it is a validator, I will start by verifying that valid objects are valuable. Now we can demonstrate the code, educate users not to do stupid things, etc. - even if the validator will never be implemented further. After that, I start adding edges with the most dangerous validation errors.

If I start with a parser and not start with an empty line, I can start with something typical, but simple, that I want to parse, and something that I would like to get from this. For me, unit tests are more like examples of how I want to use code.

I also follow the practice of BDD naming of tests should - so for your example I will have shouldReturnNullIfTheInputIsEmpty() . This helps me determine the next important thing that code should do.

It is also associated with BDD "outside." Here are some blog posts I wrote that might help: Pixie Driven Development and Error- Based Development . Bug Driven Development helps me figure out what the next bit of functionality should be at the system level, which then helps me find the next unit test.

I hope this gives you a slightly different perspective, at least good luck!

+2
source

To begin with, I will choose a simple typical case and write a test for it.

While I am writing the implementation, I will pay attention to the corner cases that my code is processing incorrectly. Then I will write tests for these cases.

Otherwise, I will look for things that this function should perform, but does not.

+1
source

All Articles