In the previous post, I gave an overview of how to get started with TDD. I tried to highlight the thought process and steps that I take when doing TDD. In this article I will continue building further on the shopping cart from the previous post and show how I can add further functionality to it using TDD. The tests that I want to focus in this article are the following:
Adding an item multiple times
Removing an item
Adding an item that is out of stock
First I want to add tests for adding an item multiple times. Currently where we left of in the previous article, we do not cater for this scenario. Currently we are only returning the count of the items in the cart and there is no mechanism for storing the quantity of individual item. The tests that I will focus on now will make me implement this functionality. Let’s look at the code for the first test.