I am experimenting with test-driven development, and I found that I often come to a following situation:
- I write tests for some functionality X. Those tests fail.
- While trying to implement X, I see that I need to implement some feature Y in a lower layer of my code. So...
- I write tests for Y. Now both tests for X and Y fail.
Once I had 4 features in different layers of code being worked on at the same time, and I was losing my focus on what I am actually doing (too many tests failing at the same time).
I think I could solve this by putting more effort into planning my tasks even before I start writing tests. But in some cases I didn't know that I will need to go deeper, because e.g. I didn't know the API of lower layer very well.
What should I do in such cases? Does TDD have any recommendations?