Covering Coverage

Coverage identifies the parts of the codebase that do not have tests.

Why do we need it?

Five questions often arise in software development and test automation:

  1. Can I refactor my code quickly and safely?
  2. Is my application robust? Will it break under certain conditions?
  3. Are there enough behavioural tests for the application we’ve built?
  4. Are my tests actually testing anything useful?
  5. Do my behavioural tests address the business requirements?

How does it help?

Coverage can play a valuable role in helping to address the questions asked above:

  1. Can I refactor my code quickly and safely? Knowing that we have sufficient unit test code coverage (at branch level) supports a ‘fail fast’ way of working and helps to document the expected technical behaviour of our units, which help Devs refactor quickly and safely.
  2. Is my application robust? Maintaining good levels of unit test coverage give us confidence that there are few lines of code that are untested, so we know that the app is unlikely to fail with a code exception.
  3. Are there enough behavioural tests? Code coverage against behavioural tests (expressed in business terms) gives us confidence that we’ve met the customer’s requirements more accurately. Sufficient coverage at this level reduces the likelihood of bugs being found later in the cycle in exploratory testing which can be costly and time-consuming.
  4. Are my tests actually testing anything useful? In support of code coverage, mutation tests measure the integrity of the unit and behavioural tests, thus giving us confidence that the tests are enforcing behaviour as opposed to just running code.
  5. Do my behavioural tests address the business requirements? The final question is a tricky one, but a high-level testability matrix can be developed to cross reference the key business use cases against suites of tests. Additionally, behavioural tests should be written in a style (with reports) that QAs and POs can review.

Usage

How we implement coverage is important. We should avoid striving for an ideal target coverage, but instead aim to prevent reductions in coverage and focus on areas of patently insufficient coverage. The coverage metrics should be used as an invitation for a discussion, perhaps at the PR stage, rather than a weapon of policing quality. Generally it’s best to let the engineering team decide when and how to use it.

Tools

Some examples covering Caplin’s tech stack:

Leave a Reply

Your e-mail address will not be published. Required fields are marked *