I am attempting to do TDD right ! I was reading about the TDD Inside Out as opposed to Outside In. Reason being is that i don't know how my layers up front so my idea was to start writing a test, have it fail and then start writing my first layer.
While writing my first layer I notice that I need another layer, lets call it a service layer. This is where I get confused, what do I do here ?
Do I stop and create a new Test that fails so that I can implement my new service layer using TDD? Once done, I go back to my original layer and should I create a mock of my service layer here ? Or use the service layer I just create via TDD?
This is TDD right ? So if I am mocking things out then maybe my TDD is not driving my development ? But of course if I don't mock things out, these technically are not unit tests but more of integration tests ?
If indeed my unit tests (written via TDD) use mocks then I need to have some other kind of tests to test the integration of each individual layer as one unit ??
An integration test or e2e test?
I think my problems are basically when I need to introduce new layers, should I mock these out, should I create a new test to drive the development of this new layer?
I hope somebody can help with untangling this muddle I have myself in !
Thanks
When developing in TDD style you should work with interfaces as much as possible.
Unit testing means that you test every unit isolated from most (ideally all) other code.
So in your case: if the code you currently work on needs to make calls to some service layer. then jsut create an interface for the new modules and mock their correct behaviour (or expected error behaviour if you want to test error handling).
... and put testing your new service layer on your todo list ;)
This way you concentrate your work on your current unit and have an interface ready for your service layer, when you start working on this.
if you want to test how your layers work together, you need some kind of integration test.