Quality in Testing not Quantity
One of the hardest parts of Continuous Confidence is understanding what brings confidence to our testing. We strive, at times, to find that proper level of confidence. Too often, we talk about Code Coverage. We want to make sure that we are touching everything, and it lifts our confidence, falsely, to the same level of as our code coverage. If we have 60% code coverage, then we have 60% confidence. The issue, however, is after a while, we start to realize, once we get bugs, that we aren't really that confident in our code and then we dismiss testing almost as a chore instead of a tool. So how do we get more confidence? Well, the answer is simple, the process a little more difficult: write quality tests.
Area Coverage
The first thing we need to do, is understand what we are testing. We should be considering Area Coverage instead of Code Coverage. Area Coverage looks at the areas of the application that have tests. There aren't a whole lot of tools out there that will help you do this. I have one I will be releasing shortly, that I use on a daily basis, but ultimately, we can do this however. Once we know that what we are testing applies directly to the requirements, we can start to understand what we are missing. Now, we can start to focus on quality tests.
Test The Change
First and foremost, we want to make sure we are testing what we change. Don't worry about other parts not being tested, unless we are trying to make up for test debt. Sorry about the changes. Test the stuff we are writing to make sure we are covering the logic.
Test The Logic
Next, test the logic. If we have a method that only returns another methods results, the confidence gained testing the latter far out ways the first. So test the latter. Test where the logic is. Test to make sure we are covering all of the logic and code paths within a method. Use constructs to limit our assumptions.
Test the Assumptions
Finally, when we look at the code we are testing, we need to test our assumptions. For example, consider the following code:
if(username.split("-")[1]) {
}
Now, there are a couple of assumptions here. What are they? First, we assume that username is not null. Second we assume that username is a string. Third we assume that when splitting the string, he length of the resultant array is greater than 1. So here is where we can write tests. Or, we can use what we learned and change the code to be hardened.
Continuous Confidence Focusses on Quality
Ultimately, we want clean and quality code. We want to be confident in what we do. Using testing to teach us what we are missing, allows us to more easily be confident that it won't break when we had it off to someone. This will allow us to be faster. This will ultimately give us Continuous Confidence in future releases.
Comments
Post a Comment