Aussie AI

Test Coverage

  • Book Excerpt from "Generative AI in C++"
  • by David Spuler, Ph.D.

Test Coverage

Test coverage is the concept of checking that your testing code is executing all the features of the program. The idea is to run your entire suite of unit tests and regression tests, and then get a report showing which parts of the code didn't get executed.

There are multiple levels of test coverage:

  • Function coverage. Which functions didn't get called?
  • Line coverage. Which lines of code didn't get executed?
  • Branch coverage. Which sections of loops or if-else tests didn't get run through?
  • Condition coverage. Which if-tests and loop-conditions didn't check both the true and false sections?

It's hard to get to 100% coverage on any of the metrics, let alone all of them. Your goal should probably to have these metrics increasing over time, rather than seeking perfection as the goal. Note that you can't get to 100% coverage easily even with function coverage because much of the code will be exception handling. There are special ways to test exception handling, such as by intentionally injecting failures (e.g. memory allocation failure), but they add to the testing workload.

 

Next:

Up: Table of Contents

Buy: Generative AI in C++: Coding Transformers and LLMs

Generative AI in C++ The new AI programming book by Aussie AI co-founders:
  • AI coding in C++
  • Transformer engine speedups
  • LLM models
  • Phone and desktop AI
  • Code examples
  • Research citations

Get your copy from Amazon: Generative AI in C++