TDD Of ShoppingCart
Over the last few months, I’ve published blog articles on developing a ShoppingCart
class applying TDD. These articles came out every so often. I recently realised that it’s hard to follow the thinking behind the TDD development process without readily seeing previous write-ups. So, I’ve gone through the collection of TDD blogs developing the ShoppingCart
class and listed them here in the correct order. I’ve provided a short outline of each blog.
ShoppingCart
Construction:
- A Little TDD We have no
ShoppingCart
class. How do we write a test to create it? - The 3 Rules Of TDD Explains the three rules of TDD. When constructing a new
ShoppingCart
instance, it costs $0. - TDD Continued Let’s ensure a new
ShoppingCart
instance has no contents and is empty.
ShoppingCart Add()
method:
- Adding A Method With TDD We want to put items into
ShoppingCart
. Let’s write tests to create anAdd()
method. - Adding A Parameter To A Method With TDD
Add()
does not have any parameters. Here we discover how to use tests to force aProduct
parameter onShoppingCart
. - TDD – Validate Shopping Cart Quantity When adding products into a
ShoppingCart
, we must also specify a quantity. What if the quantity is 0? - TDD – Add Exception Message Here we flesh out a validation exception with an exception message – the TDD way.
- TDD – Invalid ShoppingCart Quantity We can’t put -2 number of items into a
ShoppingCart
. Let’s write some tests to handle this case. - TDD – Invalid ShoppingCart Quantity (Part 2) In this blog, we are modifying the negative quantity validation from a specific number to any negative number.
- TDD – Invalid ShoppingCart Quantity (Part 3 – Refactor) Here we are simplifying the
ShoppingCart
invalid quantity validation.
As I publish more blogs on the further TDD development of ShoppingCart
, I’ll add them to the list.
Leave a Reply
Want to join the discussion?Feel free to contribute!