Mutation testing
In Chapter 2, we talked about code coverage – that is, by running the tests while measuring, we can determine how much of the code is covered by the tests. That example was by metaphor, of a dog park. We can, however, look at the actual lines of code and ask if they are executed when the test runs. The number of lines of code executed divided by the total lines of code is the statement coverage. There are problems with this approach that we’ll discuss in Chapter 9, but we hope you can agree that having such a number is generally better than nothing. Speaking of ways, there is another, slightly tricky way to see how sufficient unit tests are. We could change the code itself to perhaps compile, yet intentionally break. For example, we could change hard-coded TRUE
statements to FALSE
, remove a line of code that includes a method call, change the order in which parameters are passed into a method, and so on.
This involves changing the production code in...