Tests are executable requirements
In the first test, we wrote a very simple test that checked whether a new Stock
class has its price
attribute initialized to None
. We can now think about what requirement we want to implement next.
An observant reader might have caught on to the terminology used in the previous sentence, where I said that we can think about the requirement to implement next, instead of saying that we can think about the test to write next. Both statements are equivalent, because in TDD, tests are nothing but requirements. Each time we write a test and implement code to make it pass, what we actually do is make the code meet some requirement. Looking at it another way, tests are just executable requirement specifications. Requirement documentation often goes out of sync with what is actually implemented, but this is impossible with tests, because the moment they go out of sync, the test will fail.
In the previous chapter, we said that the Stock
class will be used to hold...