{"id":13411282,"url":"https://github.com/vladopajic/go-test-coverage","last_synced_at":"2025-12-26T00:46:29.656Z","repository":{"id":147538898,"uuid":"618927215","full_name":"vladopajic/go-test-coverage","owner":"vladopajic","description":"go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold","archived":false,"fork":false,"pushed_at":"2025-03-25T11:23:08.000Z","size":429,"stargazers_count":141,"open_issues_count":2,"forks_count":22,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T12:27:45.141Z","etag":null,"topics":["badge","code-coverage","coverage","coverage-report","developer-tools","github-actions","go","go-coverage","go-test","go-test-coverage","go-testing","go-tools","golang","golang-action","golang-coverage","golang-coverage-profile","test-coverage","testing","testing-tools","unit-test"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vladopajic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["vladopajic"]}},"created_at":"2023-03-25T18:48:25.000Z","updated_at":"2025-03-25T11:22:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc43a397-8dce-44ed-8c98-868f76517fe3","html_url":"https://github.com/vladopajic/go-test-coverage","commit_stats":{"total_commits":203,"total_committers":6,"mean_commits":"33.833333333333336","dds":0.5270935960591133,"last_synced_commit":"21fedf063813338fbc9f61df8082f512988364ca"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladopajic%2Fgo-test-coverage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladopajic%2Fgo-test-coverage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladopajic%2Fgo-test-coverage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladopajic%2Fgo-test-coverage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vladopajic","download_url":"https://codeload.github.com/vladopajic/go-test-coverage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234921,"owners_count":20905854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["badge","code-coverage","coverage","coverage-report","developer-tools","github-actions","go","go-coverage","go-test","go-test-coverage","go-testing","go-tools","golang","golang-action","golang-coverage","golang-coverage-profile","test-coverage","testing","testing-tools","unit-test"],"created_at":"2024-07-30T20:01:12.641Z","updated_at":"2025-12-26T00:46:29.650Z","avatar_url":"https://github.com/vladopajic.png","language":"Go","funding_links":["https://github.com/sponsors/vladopajic"],"categories":["Testing","Continuous Integration","持续集成","Template Engines","测试"],"sub_categories":["Testing Frameworks","Standard CLI","标准CLI"],"readme":"# go-test-coverage\n\n[![test](https://github.com/vladopajic/go-test-coverage/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/vladopajic/go-test-coverage/actions/workflows/test.yml)\n[![action-test-docker](https://github.com/vladopajic/go-test-coverage/actions/workflows/action-docker-test.yml/badge.svg?branch=main)](https://github.com/vladopajic/go-test-coverage/actions/workflows/action-docker-test.yml)\n[![action-test-source](https://github.com/vladopajic/go-test-coverage/actions/workflows/action-source-test.yml/badge.svg?branch=main)](https://github.com/vladopajic/go-test-coverage/actions/workflows/action-source-test.yml)\n[![lint](https://github.com/vladopajic/go-test-coverage/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/vladopajic/go-test-coverage/actions/workflows/lint.yml)\n[![coverage](https://raw.githubusercontent.com/vladopajic/go-test-coverage/badges/.badges/main/coverage.svg)](/.github/.testcoverage.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/vladopajic/go-test-coverage?cache=v1)](https://goreportcard.com/report/github.com/vladopajic/go-test-coverage)\n[![Release](https://img.shields.io/github/release/vladopajic/go-test-coverage.svg?color=%23007ec6)](https://github.com/vladopajic/go-test-coverage/releases/latest)\n\n![go-test-coverage cover image](https://github.com/user-attachments/assets/2febc74e-7437-4dc6-87a4-0ca47f8e714e)\n\n`go-test-coverage` is a tool designed to report issues when test coverage falls below a specified threshold, ensuring higher code quality and preventing regressions in test coverage over time.\n\n## Why Use go-test-coverage?\n\nHere are the key features and benefits:\n\n- **Quick Setup**: Install and configure in just 5 minutes.\n- **Serverless Operation**: No need for external servers, registration, or permissions.\n  - Eliminates connectivity or server-related failures.\n- **Data Privacy**: All coverage checks are done locally, so no sensitive information leaks to third parties.\n  - Learn more about [information leakage risks](https://gist.github.com/vladopajic/0b835b28bcfe4a5a22bb0ae20e365266).\n- **Performance**: Lightning-fast execution (e.g., ~1 second on [this repo](https://github.com/vladopajic/go-test-coverage/actions/runs/19500646271/job/55814181873)).\n- **Versatility**: Can be used both locally and in CI pipelines.\n- **Customizable**: Extensive configuration options to fit any project's needs.\n- **Stylish Badges**: Generate beautiful coverage badges for your repository.\n- **Coverage Diff**: Detailed comparison of code coverage changes relative to the base branch.\n- **Open Source**: Free to use and contribute to!\n\n## Usage\n\nYou can use  `go-test-coverage` in two ways:\n - Locally as part of your development process.\n - As a step in your GitHub Workflow.\n\nIt’s recommended to utilize both options for Go projects.\n\n### Local Usage\n\nHere’s an example `Makefile` with a `check-coverage` command that runs `go-test-coverage` locally:\n\n\n```makefile\nGOBIN ?= $$(go env GOPATH)/bin\n\n.PHONY: install-go-test-coverage\ninstall-go-test-coverage:\n\tgo install github.com/vladopajic/go-test-coverage/v2@latest\n\n.PHONY: check-coverage\ncheck-coverage: install-go-test-coverage\n\tgo test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...\n\t${GOBIN}/go-test-coverage --config=./.testcoverage.yml\n```\n\n### GitHub Workflow\n\nHere’s an example of how to integrate `go-test-coverage` into a GitHub Actions workflow:\n\n\n```yml\nname: Go test coverage check\nruns-on: ubuntu-latest\nsteps:\n  - uses: actions/checkout@v3\n  - uses: actions/setup-go@v3\n  \n  - name: generate test coverage\n    run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...\n\n  - name: check test coverage\n    uses: vladopajic/go-test-coverage@v2\n    with:\n      config: ./.testcoverage.yml\n```\n\nFor detailed information about the GitHub Action, check out [this page](./docs/github_action.md).\n\n### Configuration\n\nHere’s an example [.testcoverage.yml](./.testcoverage.example.yml) configuration file:\n\n```yml\n# (mandatory) \n# Path to coverage profile file (output of `go test -coverprofile` command).\n#\n# For cases where there are many coverage profiles, such as when running \n# unit tests and integration tests separately, you can combine all those\n# profiles into one. In this case, the profile should have a comma-separated list \n# of profile files, e.g., 'cover_unit.out,cover_integration.out'.\nprofile: cover.out\n\n# Holds coverage thresholds percentages, values should be in range [0-100].\nthreshold:\n  # (optional; default 0) \n  # Minimum coverage percentage required for individual files.\n  file: 70\n\n  # (optional; default 0) \n  # Minimum coverage percentage required for each package.\n  package: 80\n\n  # (optional; default 0) \n  # Minimum overall project coverage percentage required.\n  total: 95\n\n# Holds regexp rules which will override thresholds for matched files or packages \n# using their paths.\n#\n# First rule from this list that matches file or package is going to apply \n# new threshold to it. If project has multiple rules that match same path, \n# override rules should be listed in order from specific to more general rules.\noverride:\n  # Increase coverage threshold to 100% for `foo` package \n  # (default is 80, as configured above in this example).\n  - path: ^pkg/lib/foo$\n    threshold: 100\n\n# Holds regexp rules which will exclude matched files or packages \n# from coverage statistics.\nexclude:\n  # Exclude files or packages matching their paths\n  paths:\n    - \\.pb\\.go$    # excludes all protobuf generated files\n    - ^pkg/bar     # exclude package `pkg/bar`\n\n# (optional; default false)\n# When true, requires all coverage-ignore annotations to include explanatory comments\nforce-annotation-comment: false\n\n# If specified, saves the current test coverage breakdown to this file.\n#\n# Typically, this breakdown is generated only for main (base) branches and \n# stored as an artifact. Later, this file can be used in feature branches \n# to compare test coverage against the base branch.\nbreakdown-file-name: ''\n\ndiff:\n  # Path to the test coverage breakdown file from the base branch.\n  #\n  # This file is usually generated and stored in the main (base) branch,\n  # controled via `breakdown-file-name` property.\n  # When set in a feature branch, it allows the tool to compute and report \n  # the coverage difference between the current (feature) branch and the base.\n  base-breakdown-file-name: ''\n\n  # Allowed threshold for the test coverage difference (in percentage) \n  # between the feature branch and the base branch.\n  #\n  # By default, this is disabled (set to null). Valid values range from \n  # -100.0 to +100.0.\n  #\n  # Example: \n  #   If set to 0.5, an error will be reported if the feature branch has \n  #   less than 0.5% more coverage than the base.\n  #\n  #   If set to -0.5, the check allows up to 0.5% less coverage than the base.\n  threshold: null\n```\n\n### Exclude Code from Coverage\n\nFor cases where there is a code block that does not need to be tested, it can be ignored from coverage statistics by adding the comment `// coverage-ignore` at the start line of the statement body (right after `{`).\n\n```go\n...\nresult, err := foo()\nif err != nil { // coverage-ignore\n\treturn err\n}\n...\n```\n\nSimilarly, the entire function can be excluded from coverage statistics when a comment is found at the start line of the function body (right after `{`).\n```go\nfunc bar() { // coverage-ignore\n...\n}\n```\n\n## Generate Coverage Badge\n\nYou can easily generate a stylish coverage badge for your repository and embed it in your markdown files. Here’s an example badge: ![coverage](https://raw.githubusercontent.com/vladopajic/go-test-coverage/badges/.badges/main/coverage.svg)\n\nInstructions for badge creation are available [here](./docs/badge.md).\n\n## Visualise Coverage\n\nGo includes a built-in tool for visualizing coverage profiles, allowing you to see which parts of the code are not covered by tests.\nFollowing command will generate `cover.html` page with visualized coverage profile: \n```console\ngo tool cover -html=cover.out -o=cover.html\n```\n\n## Support the Project\n\n`go-test-coverage` is freely available for all users. If your organization benefits from this tool, especially if you’ve transitioned from a paid coverage service, consider [sponsoring the project](https://github.com/sponsors/vladopajic). \nYour sponsorship will help sustain development, introduce new features, and maintain high-quality support. Every contribution directly impacts the future growth and stability of this project.\n\n⭐ Love this project? Star it!\n\nThis tool is still not widely known, and giving the repository a ⭐️ is a simple, cost-free way to help it gain visibility. It’s a win-win for everyone: new users discover a useful tool they might have otherwise missed, and existing users benefit from a larger community where issues get identified sooner, improvements happen faster and new contributions help the project grow.\n\n## Contribution\n\nAll contributions are welcome - whether you're fixing a typo, adding a new feature, or reporting an issue. Feel free to open a pull request or create an issue to contribute!\n\nSee the [contributing](/docs/contributing.md) page for more details before opening a PR.\n\n---\n\nHappy coding 🌞\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladopajic%2Fgo-test-coverage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvladopajic%2Fgo-test-coverage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladopajic%2Fgo-test-coverage/lists"}