Testing and TDD talk with live coding examples

Posted by Andy Huggins on May 19, 2016

I think TDD is a buzz word going around these days, has been for a few years. It has sort of morphed to represent the idea of Automated Tests in general, although I think this is just Testing and TDD is a specific approach.

Testing is done with all code. That can mean anything from refreshing a browser, to whether or not the application compiles, or just running code in a command line interface. At some point in the development of applications, the code is tested...either by you or your users.

Automated testing, allows for use cases to be defined and the operation of those definitions can be verified by testing frameworks, often faster than testing in a browser.

TDD relies heavily on the idea of Automated Testing, with an emphasis on writing tests first, and then writing code to pass the tests. This requires a shift in approach by developers that is very daunting initially. TDD requires discipline and writing more code and initially it seems like you get further from "getting things done."

However, proponents of TDD argue that the automated tests allow you to more quickly and more frequently test your code fully, which allows you to see any issues sooner. Which might prevent new bugs from being introduced or taking a long time for the right edge case to present itself.

Regardless of how you feel about Testing and TDD, as a developer you should recognize them as tools that you can use, and I think it is worth some effort on your part to learn something about it in order to see if it provides value to you.

Here are some slides I put together for a brief introduction to TDD and Testing, a lot is left out of the presentation because I wanted to do a couple live coding examples with the members of the group, because I think that is the best way for people to see a new idea or concept and begin to understand it.

So if you were not at the talk, you missed out on what the group did. However, I recorded both examples as screencasts, in case anyone wanted to see what we did.

The first example is the Gilded Rose Kata. This is a pretty great example of how to use tests to refactor existing code. Here is a Github repo that you can download for yourself if you are interested in working through the problem yourself.

Here is the screencast:

The second example is something I threw together that is basically setting up a simple Shopping Cart with Products that you can Add, Total, and Remove items with. I tried to keep this simple because the time involved should already be getting long, and I wanted to show how TDD can be used to write code. Essentially, giving both takes on how Testing/TDD can be used.

Second screencast, Carts and Products (Github repo):

There is a lot more TDD and Testing in general, but the idea here is to give a brief introduction and give people an idea of how the tools can be used and the value they provide. Believe me, there are books out there that attempt to show how to Test your code, and I don't think even they fully cover everything.

Note: Both repos for the examples have a branch named `solution` that has the refactored or written code.