Testing

Everything having to do with testing: Unit testing, Integration Testing, Test Coverage

Test Coverage

It’s helpful to be able to measure how much of our code is covered by tests. This metric is known as “test coverage”

Line Versus Branch Coverage

Two common metrics are

It might be immediately obvious why those are not the same.

The answer is that not every if statement has an else.

  color="blue";
  if (x<10) {
      color="red";
  }
  foo(color);

Suppose we have a test that covers the case where x<10 evaluates to true. Then for those code, we have 100% line coverage, but we do not necessarily have 100% branch coverage unless we ALSO have a test that covers the case when x<10 evaluates to false. That means that there is a branch into calling foo(color) when color still has the value “blue”, and that branch is untested.

Tools for measuring test coverage

One such tool is Jacoco (http://www.jacoco.org/jacoco/index.html)

The documentation for Jacoco can be difficult to follow.

Here is some help:

Related topics: