{"id":15077722,"url":"https://github.com/nikita-filonov/tests-coverage-tool","last_synced_at":"2026-02-21T07:42:54.628Z","repository":{"id":257089174,"uuid":"850065983","full_name":"Nikita-Filonov/tests-coverage-tool","owner":"Nikita-Filonov","description":"Ultimate tool to measure gRPC service coverage from tests","archived":false,"fork":false,"pushed_at":"2024-12-26T18:23:38.000Z","size":2755,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T10:51:47.792Z","etag":null,"topics":["coverage","coverage-report","coverage-testing","go","golang","grpc","grpc-go","grpc-service","qa-automation","test-automation","testing","testing-tools"],"latest_commit_sha":null,"homepage":"https://nikita-filonov.github.io/tests-coverage-tool/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nikita-Filonov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-30T20:07:42.000Z","updated_at":"2025-02-16T08:23:26.000Z","dependencies_parsed_at":"2024-11-16T08:23:32.554Z","dependency_job_id":"51a839f8-20f6-45c2-96d8-7a70e7cd2a50","html_url":"https://github.com/Nikita-Filonov/tests-coverage-tool","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"838e9d1be3409cc2b3f3b32e231f1ebb220245c6"},"previous_names":["nikita-filonov/tests-coverage-tool"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikita-Filonov%2Ftests-coverage-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikita-Filonov%2Ftests-coverage-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikita-Filonov%2Ftests-coverage-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikita-Filonov%2Ftests-coverage-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nikita-Filonov","download_url":"https://codeload.github.com/Nikita-Filonov/tests-coverage-tool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173427,"owners_count":21224534,"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":["coverage","coverage-report","coverage-testing","go","golang","grpc","grpc-go","grpc-service","qa-automation","test-automation","testing","testing-tools"],"created_at":"2024-09-25T04:30:45.293Z","updated_at":"2026-02-21T07:42:54.601Z","avatar_url":"https://github.com/Nikita-Filonov.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tests coverage tool\n\nThe Tests Coverage Tool is a comprehensive utility designed to measure code coverage for gRPC services based on their\nproto contracts. It provides detailed insights into various aspects of your service's coverage, helping you ensure that\nyour tests thoroughly validate your gRPC endpoints. The tool gathers the following metrics:\n\n- **Total Coverage Percentage:** The overall coverage percentage across all services;\n- **Service-Specific Coverage:** The coverage percentage for each logical service within your gRPC API;\n- **Method Coverage:** Whether each gRPC method is covered by tests (covered/not covered);\n- **Request/Response Coverage:** Detailed coverage for each method, including the total request parameters, the number\n  of covered parameters, and the coverage percentage;\n- **Parameter-Level Coverage:** In-depth coverage details for each parameter within the request/response, allowing you\n  to see which parts of your API are thoroughly tested;\n- **Deprecation Status:** Information on whether methods and their parameters are deprecated, aiding in maintaining\n  up-to-date and clean tests;\n- **Support for Multiple Services:** The tool can handle coverage reporting for multiple gRPC services within a single\n  project;\n- **Coverage history:** The tool can maintain the history of overall service coverage, logical service coverage, and\n  coverage of gRPC method request and response parameters.\n\nYou can see a report example [here](https://nikita-filonov.github.io/tests-coverage-tool/).\n\nIf you have any questions, you can ask [@Nikita Filonov](https://t.me/sound_right)\n\n## Preview\n\n### Service coverage\n\n![Service coverage](docs/preview_service_coverage.png \"Service coverage\")\n\n### Logical services coverage\n\n![Logical services coverage](docs/preview_logical_services_coverage.png \"Logical services coverage\")\n\n### Method coverage\n\n![Method coverage](docs/preview_method_coverage.png \"Method coverage\")\n\n## Installation\n\nTo install the Tests Coverage Tool, use the following command:\n\n````shell\ngo get github.com/Nikita-Filonov/tests-coverage-tool@latest\n\n````\n\n## Usage\n\n### Client interceptor\n\nBelow is an example of how to set up the gRPC client with the coverage interceptor:\n\n```go\npackage test\n\nimport (\n\t\"context\"\n\t\"crypto/tls\"\n\t\"fmt\"\n\t\"log\"\n\t\"testing\"\n\n\tgrpcmiddleware \"github.com/grpc-ecosystem/go-grpc-middleware\"\n\t\"google.golang.org/grpc\"\n\t\"google.golang.org/grpc/credentials\"\n\n\t\"github.com/Nikita-Filonov/tests-coverage-tool/tool/coverageinupt\"\n)\n\nfunc TestGRPC(t *testing.T) {\n\t// Set up a gRPC client connection with the coverage interceptor\n\tconn, err := grpc.Dial(\n\t\t\"localhost:1000\",\n\t\tgrpc.WithTransportCredentials(credentials.NewTLS(\u0026tls.Config{InsecureSkipVerify: true})),\n\t\tgrpc.WithUnaryInterceptor(\n\t\t\tgrpcmiddleware.ChainUnaryClient(\n\t\t\t\t// Integrate the CoverageInterceptor to track method coverage\n\t\t\t\tcoverageinupt.CoverageInterceptor(),\n\t\t\t),\n\t\t),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to connect to gRPC server: %v\", err)\n\t}\n\tdefer conn.Close()\n\n\t// Initialize the proto service client\n\tclient := servicev1.NewServiceClient(conn)\n\n\t// Call a gRPC method; coverage data will be automatically saved in the specified directory\n\tresp, err := client.Get(context.Background(), \u0026servicev1.GetRequest{})\n\n\tfmt.Println(resp, err)\n}\n\n```\n\n### Generate report\n\nBefore generating the coverage report, ensure that the `tests-coverage-tool` is installed. This tool relies on server\nreflection to gather data, so your gRPC service must support server reflection; otherwise, the tool will be unable to\nmeasure service coverage.\n\nTo install the tool, run:\n\n```shell\ngo install github.com/Nikita-Filonov/tests-coverage-tool/...@latest\n```\n\nOnce installed, you can generate the coverage report with the following command:\n\n```shell\ntests-coverage-tool save-report\n\n```\n\nThis will generate a coverage report based on the results gathered during your test runs.\n\n### State\n\nThe library includes a built-in function, `report.ReadCoverageReportState`, which simplifies reading the state from a\nJSON coverage report. This function serves as a helper for analytics and reporting purposes, allowing users to\nefficiently manage the output of a JSON coverage report\n\nHere’s an example of how to use it:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/Nikita-Filonov/tests-coverage-tool/tool/report\"\n)\n\nfunc main() {\n\t// Read the coverage report state from the JSON file\n\tstate, err := report.ReadCoverageReportState()\n\tif err != nil {\n\t\tlog.Fatalf(\"Error reading coverage report state: %v\\n\", err)\n\t}\n\n\t// Perform actions with the coverage state\n\tfmt.Println(state)\n}\n\n```\n\nIn this example, the `ReadCoverageReportState` function reads the JSON coverage report, and you can then process the\nstate variable for further analytics or reporting\n\n## Config\n\nThe tool can be configured via environment variables or a YAML configuration file. Below are the available options:\n\n| Environment                            | YAML                  | Default               | Example                                                                                                                                                                                                                                   |\n|----------------------------------------|-----------------------|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| —                                      | services              | —                     | Defines the gRPC services to monitor. See the example configuration file at [./docs/config-example.yaml](docs/config-example.yaml)                                                                                                        |\n| TESTS_COVERAGE_CONFIG_FILE             | —                     | —                     | Path to the YAML configuration file. Example: [./docs/config-example.yaml](docs/config-example.yaml)                                                                                                                                      |\n| TESTS_COVERAGE_RESULTS_DIR             | resultsDir            | .                     | Directory where coverage results will be stored. Example: if set to `./tests`, results will be stored in `./tests/coverage-results`                                                                                                       |\n| TESTS_COVERAGE_HISTORY_DIR             | historyDir            | .                     | Directory where the history will be saved                                                                                                                                                                                                 |\n| TESTS_COVERAGE_HISTORY_FILE            | historyFile           | coverage-history.json | Name of the history file                                                                                                                                                                                                                  |\n| TESTS_COVERAGE_HTML_REPORT_DIR         | htmlReportDir         | .                     | Directory where the HTML report will be saved                                                                                                                                                                                             |\n| TESTS_COVERAGE_JSON_REPORT_DIR         | jsonReportDir         | .                     | Directory where the JSON report will be saved                                                                                                                                                                                             |\n| TESTS_COVERAGE_HTML_REPORT_FILE        | htmlReportFile        | index.html            | Name of the HTML report file                                                                                                                                                                                                              |\n| TESTS_COVERAGE_JSON_REPORT_FILE        | jsonReportFile        | coverage-report.json  | Name of the JSON report file                                                                                                                                                                                                              |\n| TESTS_COVERAGE_HISTORY_RETENTION_LIMIT | historyRetentionLimit | 30                    | Defines the maximum number of the most recent coverage history records to be retained. In this case, the value `30` means that only the latest 30 entries in the coverage history will be preserved, and older entries will be discarded. |\n\n## History\n\nTo save coverage history, you must retain the history file, which is configured using the environment variables\n`TESTS_COVERAGE_HISTORY_DIR` and `TESTS_COVERAGE_HISTORY_FILE`. By default, the history file will be stored in the root\ndirectory with the name `coverage-history.json`. You do not need to create this file manually—it will be automatically\ngenerated when you run the save-report command. After that, you simply need to keep the `coverage-history.jso`n file for\nsubsequent report generations. Each time a new report is generated, the file will be automatically updated with the\nlatest coverage history, and the history will be added to the coverage report.\n\nIf you wish to disable the coverage history functionality, you can set the `TESTS_COVERAGE_HISTORY_DIR` and\n`TESTS_COVERAGE_HISTORY_FILE` environment variables to empty strings. This can be done through the YAML configuration\nfile using the `historyDir` and `historyFile` settings.\n\n## Commands\n\n### Save report\n\nTo save a coverage report, use the following command:\n\n```shell\ngo run ./tests-coverage-tool/main.go save-report\n```\n\nThis command will generate and save the coverage report based on the collected test data.\n\n### Copy report\n\nTo update and merge submodules and then copy the report, run:\n\n```shell\ngit submodule update --init --recursive\ngit submodule update --remote --merge\n\ngo run ./tests-coverage-tool/main.go copy-report\n\n```\n\nThis command is useful for syncing submodules and copying the report to the desired location.\n\n### Print config\n\nTo print the current configuration, use the following command:\n\n```shell\ngo run ./tests-coverage-tool/main.go print-config\n\n```\n\nThis command outputs the configuration settings currently in use, allowing you to verify and adjust as needed\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikita-filonov%2Ftests-coverage-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikita-filonov%2Ftests-coverage-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikita-filonov%2Ftests-coverage-tool/lists"}