small medium large xlarge

04 Aug 2010, 23:47
Oliver Searle-Barnes (1 post)

I’ve been practising TDD for about 4 years now. An area that I found particularly useful was tests for code that delegate to an unfamiliar API, in this case Tyrant’s http interface. Typically when faced with this scenario I’ll spend some time writing code without tests to explore the new API. I’ll then throw this code away and proceed in a TDD fashion with my new knowledge of how the API I’m delegating to behaves. This is particularly the case where an API spans several classes and I don’t know what I’m even going to need references to. My big takeaway from this series was seeing how you can frame your exploration of a new API in tests and then smoothly turn that exploration into writing actual code that you’re going to use.

I’m currently working in ruby where the REPL makes it even more tempting to skip writing the tests initially. I’m now aware of how this initially fast method of exploration quickly becomes really inefficient. Often I’ve found myself repeating lines of code in the REPL that could have been so much easier to play with had I only done so in a test.

  You must be logged in to comment