Breaking down obscure tests into simple ones
Unittest provides the means to test the code through a series of assertions. I have often felt the temptation to exercise many aspects of a particular piece of code within a single test method. If any part fails, it becomes obscured as to which part failed. It is preferable to split things up into several smaller test methods, so that when some part of the code under test fails, it is obvious.
How to do it...
With these steps, we will investigate what happens when we put too much into a single test method.
- Create a new file named
recipe8.pyin which to put our application code for this recipe.
- Pick a class to test. In this case, we will use an alternative version of the Roman numeral converter, which converts ...