TDD is "backwards"

Down-Under?

Jan Olbrich
Mobile Quality
2 min readSep 12, 2017

--

While teaching TDD to colleagues, often the same question arose:

Where do we start to develop software?

This question led to quite some discussions and hardship understanding TDD.

I've seen different approaches where to start, but most often people tend towards the User-Interface. The reason for this is being able to execute an interaction and see if they've implemented the correct behavior.

Doing this in TDD is quite tedious. You start with a button and check if it's not nil. Okay that's the case… When pressing the button, I want to see the list of (e.g.) movies the user searched for. Hmm I can't test that yet, as I don't have any data yet! What to do?

One option would be to pass in fake data and replace it piece by piece with actual data every time we add some code. This seems to work fine, till you realize it's a lot of work and development slows to a crawl.

Another option is to not start with the User-Interface. Instead start with the network request. Starting here, your tests know exactly what to expect and are testing live data, instead for your mocks (of course the next step is to stub the requests, but we're not there yet). Having written our request, we can add parsing, then maybe storage etc. All through this, we know we have working code which is not based on assumptions.

One problem starting bottom up are shareholders. They want to see changes in your software and creating a network stack is nothing they can see. Do not fall in the trap of mocking all the data and creating only user interfaces to make shareholders happy. At some point, you will have to write the rest and then they will complain even more, since development was fast and now there is nothing new anymore.

This is no other idea, than the default TDD practice:

Start with the smallest piece of code you'll need and write a test for this.

Conclusion

Getting this idea in someones head is not as easy as it seems to be. It requires discipline to write a test first and not to add more code than necessary. Still having this discipline and sticking to it will yield tremendous results and the idea written above will just help you getting started. Practicing TDD will by itself lead to to this conclusion.

If not I'd love to hear about it!

Next: Advanced Mocks in Swift

Previous: What about Networking?

--

--

Jan Olbrich
Mobile Quality

iOS developer focused on quality and continuous delivery