Code coverage

Android Studio has a built-in feature that allows you to run tests with code coverage.

Simply navigate to the src/test/java folder and right click. Then select Run ‘Tests in ‘java’’ with Coverage (awkward use of single quotes theirs not mine).

The result will give you a window that displays test coverage by package, class, method, and lines.

This can be a useful tool to get a coarse indication of how well tested a project is at the current moment. Using code coverage as a long term metric or goal is a more dubious proposition.

As this tweet suggests there are more important goals than 100% code coverage. But the real danger is when code coverage becomes a numbers game.

Coverage for 100% of lines is not the same coverage for 100% of code paths.

Applying the Pareto principle what is the benefit of 100% versus say 80% coverage?

Finally if for those practicing TDD code coverage can be 100% useless as the development process itself should ensure proper coverage of all features and bug fixes as (before) they are written.

Like what you read? Give Chuck Greb a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.