More On The Thorns Of TDD
Yesterday’s TDD concept was that of The Thorns and The Gold. We discovered that thorns are exception conditions. That is true. However, thorns are also two other things: Ancillary Data and Degenerate Conditions.
The idea is that we cover off thorns in the following order:
- Ancillary data,
- Degenerate conditions, and finally
- Exception scenarios
1. Ancillary Data
At times supporting information is required before we can write a test. For example, to unit test the calculation of GstAmount for an Invoice class, we will require knowledge of the current GST percentage inside Invoice. Maybe class Invoice could publically expose a GstPercentage property? It’s only the unit test for GstAmount that needs access to GstPercentage:
invoice.GstAmount.Should().Be(invoice.TotalAmount * invoice.GstPercentage);
There is no other requirement for the availability of GstPercentage on Invoice. GstPercentage only supports the development of GstAmount and is therefore purely ancillary.
2. Degenerate Conditions
The definition of degenerate that works best here is the idea of a simplified or basic state of the class under development. For example, an empty ShoppingCart class is the simplest, most basic version of a shopping cart – it’s the degenerate version. Empty carts work just like full ones: We can access the contents – it’s just that there is nothing there. We can obtain the total cost or amount – and it should be $0.
Often (but not always) these ancillary conditions are starting positions:
- Shopping carts before starting shopping – Cost of $0
- Races that haven’t started – Time of 0:00
- Games that haven’t started – Score of 0 : 0
- New bank accounts – $0 balance
- and so on. You get the idea.
3. Exception Scenarios
Last but not least, these are the error scenarios that we have covered off in the previous post. All the things that can go wrong due to invalid or absent data is a thorn to snag us and could destabilise our system. We want to cover these off.