Code coverage
Understanding the extent of code coverage ensures that your tests adequately exercise your code base. Go provides a built-in tool called cover
that generates test coverage reports based on the test cases you have implemented and that it can identify. This is something you can easily add for unit tests and is a new feature that was added in Go 1.20 for integration test code coverage.
Industry standards for application development sit at an 80% code coverage average for projects to strive for. You will typically see the coverage tool used in CI tools that run pull requests against main/master branches to check that there are no large drops in code coverage that have been tested.
You can add the cover
flag to calculate test coverage on your test functions. There is also a flag that you can include to specify an output file to generate from the code coverage tool running and gathering its results. This is a useful report to include when your project requires artifacts...