Code coverage measures how much production code a test suite exercises. Its practical use is to find code that still needs tests. In a microservice, run coverage alongside automated tests so changes to a service can be checked without manually testing the entire system. section 7.5 section 7.0
Use Go’s built-in tools to move from a package percentage to a report you can inspect:
- Run `go test -cover ./...` to see coverage for each package with its test result. The reported percentage is statement coverage. section 7.5
- Run `go test ./... -cover -coverprofile=coverage.out` to save coverage data. Then run `go tool cover -html=coverage.out` to inspect its distribution across files and functions. section 7.2.4 section 7.5.1
- Pass `coverage.out` to CI checks on pull requests. A configured threshold can fail a check when coverage drops, prompting another look at the tests. section 7.5.1 section 7.5.2
Coverage for an Order service
Tests of `PlaceOrder` can mock database and payment calls, checking a successful order, a persistence error, and a payment error. Run coverage after these tests to see how much of the package they exercise and where further tests are needed. A percentage is a guide to exercised code, not a substitute for checking the behavior each test asserts. section 7.2.4 section 7.5
ok github.com/huseyinbabal/microservices/order/internal/application/core/a pi 0.274s coverage: 93.3% of statements
The sample Go test result reports 93.3% statement coverage for one package. section 7.5













