Most requirements are statements of desired behavior. But there can be implications behind these requirements concerning behavior that is not desired.
For example, we might test-drive a value object that represents some domain information, and the requirement for it might include that the object must be “immutable.” The implication would be that the object has no mutator methods allowing the values contained to be altered.
How can we write a test that specifies that a method does not exist? Continue reading “Specifying the Negative in TDD”
Here is a bit of a thought experiment, first suggested to me by Eran Pe’er.
Imagine there are two magic buttons in front of you. You know, without any doubt that if you press Button A then your code will suddenly have 90% code coverage. If you push Button B, you will have 80% code coverage.
But there is another difference. Continue reading “TDD and the Magic Buttons”
Software is quite often implemented in the context of reusable frameworks and other preexisting, valuable entities. As our industry matures it becomes increasingly true that we don’t need to re-invent the wheel
For example, if code is written that is required to send data over a TCP-IP connection in, say, C#, the tendency is for the developer to use the built-in Socket class that is part of .Net. Why would a developer create their own such entity? It makes sense to reuse what is well tested and proven over time to be effective. Continue reading “TDD and Inflection Points”
TDD tests need to be run frequently. As an agile process, TDD needs to be responsive and flexible. Part of this is the ability to keep very short the feedback loop between tests and production.
To run tests frequently without excessive cost requires that they must be executed quickly. Here are some things that help keep tests fast. Continue reading “Keeping Tests Fast”
In TDD, we want to run the tests frequently. When we do so, it shortens the pulse of our work, increasing velocity. Also, when a test unexpectedly fails, we know that it must be something we just did that produced this result. It becomes very easy to find the error.
This means that we must be able to run tests frequently which in turn means that tests: Continue reading “Make Tests Repeatable and Independent”
It is important that the system behaviors we create as developers are both accurate and precise. These are not the same. One can be:
- Accurate, but not precise, such as “Pi is a little over three.”
- Precise, but not accurate, such as “Pi is 5.393858303895.”
They are not the same, but they are related. The level of precision required tells you how far to go in determining accuracy.
Here is an example. Continue reading “TDD and Accuracy vs. Precision”
Ideally in TDD, no more than one test is ever failing at any given point in time. This test represents the work that is about to be done but hasn’t yet. Also, this test should not spend a long time in the red. We want the suite to get back to “all green” as quickly as possible.
Here are some reasons for this: Continue reading “TDD: Keeping Tests Green”
TDD is a powerful way to develop new code. However, most organizations have significant existing code that was not developed this way. This “legacy code” is often difficult to test because it was not designed to be testable in the first place.
In his excellent book, Working Effectively with Legacy Code, Michael Feathers outlines techniques for dealing with this kind of code, with an eye toward making it more testable. This book is an essential resource for anyone that has significant legacy code. Continue reading “TDD and Legacy Code”
Refactoring is defined by Martin Fowler as “improving the design of existing code.” Refactoring stipulates two things: that behavior does not change, and that the design has been improved. While developers have been “cleaning up” their code from the very early days, Fowler made this a discipline that developers can collaborate within. He defined a shared way to do it. Continue reading “The Value of Refactoring Skills”
Abstract classes in languages like Java or C# serve two purposes: they create polymorphism in design, and they are a convenient place to put behavior that is common to all derived classes, avoiding redundancy.
But if all behavior in TDD needs to be tested, and if instance behavior implemented in abstract classes cannot be tested (because they cannot be instantiated), then how can we adhere to our process? Continue reading “TDD: Testing Adapters for Abstract Classes”