{"id":15882707,"url":"https://github.com/lust4life/coverage-diff-poc","last_synced_at":"2026-01-21T12:02:02.106Z","repository":{"id":81520943,"uuid":"275869780","full_name":"lust4life/coverage-diff-poc","owner":"lust4life","description":"Detect test case affected by code changes using jacoco coverage info","archived":false,"fork":false,"pushed_at":"2020-09-02T03:23:56.000Z","size":479,"stargazers_count":1,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T14:47:01.386Z","etag":null,"topics":["coverage-diff","jacoco"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lust4life.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-29T16:29:42.000Z","updated_at":"2022-04-26T07:56:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f04d09e-5411-4d28-982e-24d3dbb46699","html_url":"https://github.com/lust4life/coverage-diff-poc","commit_stats":{"total_commits":83,"total_committers":1,"mean_commits":83.0,"dds":0.0,"last_synced_commit":"809aa3a2914371a35b792d7203f318effd80ed93"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lust4life/coverage-diff-poc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lust4life%2Fcoverage-diff-poc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lust4life%2Fcoverage-diff-poc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lust4life%2Fcoverage-diff-poc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lust4life%2Fcoverage-diff-poc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lust4life","download_url":"https://codeload.github.com/lust4life/coverage-diff-poc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lust4life%2Fcoverage-diff-poc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28632781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-diff","jacoco"],"created_at":"2024-10-06T04:06:36.474Z","updated_at":"2026-01-21T12:02:02.089Z","avatar_url":"https://github.com/lust4life.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Scala CI](https://github.com/lust4life/coverage-diff-poc/workflows/Scala%20CI/badge.svg)\n[![codecov](https://codecov.io/gh/lust4life/coverage-diff-poc/branch/master/graph/badge.svg)](https://codecov.io/gh/lust4life/coverage-diff-poc)\n====\n\n# pre-requirement\n\n- https://www.npmjs.com/package/diff2html-cli\n\n  you need install diff2html cli tool, for diff parsing\n\n# class explanation\n\n```scala\n  // only using when you using github as your code diff locator and your source code file resolver\n  // other implementation are pluggable, e.g. gitlab, local git repo...\n  val githubRepo = GithubRepo(\"lust4life\", \"coverage-diff-poc\")\n\n  // your test case coverage store when you generate test case info by jacoco coverage info\n  val testCaseMemoryStore = new TestCaseMemoryStore()\n\n  // test case resolver using memory store\n  val testCaseResolver = new TestCaseResolverFromMemory(\"example/src/\", testCaseMemoryStore)\n\n  // find test cases which affected in diff's changed/renamed/... files\n  val testCaseResolverByDiff = new TestCaseResolverByDiff(testCaseResolver, JavaDiffFilter)\n\n  // using java parser to generate java code structure, using for detect changes by diff lines.\n  val javaCodeBlockGenerator = new JavaBlockGenerator()\n\n  // how to find source code, here using github raw file url\n  val codeBlockFilePathResolverFromGithub = new CodeBlockFilePathResolverFromGithub(githubRepo, \"master\")\n  \n  // link generator with file resolver\n  val codeBlockGeneratorByFilePath = new CodeBlockGeneratorByFilePath(javaCodeBlockGenerator, codeBlockFilePathResolverFromGithub)\n\n  // using detector to find affected test cases by compare diff changed lines and source code method structure\n  val testCaseDetector = new TestCaseDetectorByCodeBlock(codeBlockGeneratorByFilePath, testCaseResolverByDiff)\n\n  // diff stream locator from github\n  val diffStreamLocatorFromGithub = new DiffStreamLocatorFromGithub(githubRepo)\n\n  // using diff2html to parse unified diffs\n  val diffParser = new DiffParserByUnifiedDiff()\n```\n\n# find test case affected by code changes\n\n- start your service with jacoco javaagent using tcpserver as the output\n\n    - https://www.eclemma.org/jacoco/trunk/doc/agent.html\n    \n    see `utils.startJacocoAgent` in [utils.scala](./example/src/poc/example/utils.scala)\n\n- run your test case automatically or manually, then using `jacocoClient.grab()` or `jacocoClient.grabAndReset()` to get jacoco execution data\n\n    you can save execution data in file for later report generating, or your can generate test case coverage info from this execution data.\n\n    ```scala\n    val (_, execData) = utils.jacocoClient.grab()\n\n    // generate test case info from jacoco coverage and save it into memory db\n    val testCaseInfoFromJacoco = new TestCaseInfoFromJacoco()\n    val testCaseName = \"your test case name\"\n    val jarLocation = \"your service jar location path, only for helper message when error\"\n    val jarFileStream = \"your service jar file stream\"\n   \n    // analyze jacoco execution data, then generate test case info we needed\n    val bundle = testCaseInfoFromJacoco.analyzeCoverage(testCaseName, jarLocation, jarFileStream, execData)\n    testCaseInfoFromJacoco.generateTestCaseInfo(\"master\", bundle)\n      .map(testCaseMemoryStore.save)\n      .foreach(Await.result(_, Duration.Inf))\n    ```\n   \n- after generate the test case coverage info, you can find which test case affected by code changes through diff (commits or pull request)\n   \n   ```scala\n    val diffStream = diffStreamLocatorFromGithub.getDiffStreamByPullRequest(pull-request-id)\n    detectByDiffStream(diffStream)\n  \n    // or by commits\n    val diffStream = diffStreamLocatorFromGithub.getDiffStream(base, target)\n    detectByDiffStream(diffStream)\n  \n    // using diff parser to parse unified diff and then using java parser to parse source code structure\n    // then detect affected test cases\n    private def detectByDiffStream(diffStream: InputStream) = {\n      val diffFiles = diffParser.parse(diffStream)\n      val changedInfos = Await.result(testCaseDetector.detect(diffFiles), Duration.Inf)\n    }\n    ```\n   \n   \n\n# other resources\n\n- mill build for source code\n    - http://www.lihaoyi.com/mill/\n\n# using docker-compose\n\n```bash\n# make sure enable buildkit\nCOMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build\n```\n\n# show-case-spring-boot api explanation\n\n- /coverage/index.html\n\n  查看测试覆盖率报告\n  \n- /export-coverage\n\n  将 测试用例基准库 导出成 测试覆盖率报告，以供 `/coverage/index.html` 查看\n  \n- /run-test-case-automatically/:host/:port/:tcpPort\n\n  模拟自动化测试，传入所要测试服务的 host， port 以及 jacoco tcp-server 的 port，具体值参考 docker-compose/docker-compose.yml。 同时将其转化为 测试用例基准库\n  \n- /clear\n\n  清空 测试用例基准库\n  \n- /reset/:host/:tcpPort\n\n  重置所要测试服务的 jacoco 数据，以便进行干净的测试和抓取（grab）\n  \n- /grab/:host/:tcpPort?caseId=some-test-case\n\n  抓取所要测试服务的 jacoco 数据，以便生成 测试用例基准库. caseId 标识该次手动测试用例名称\n  \n- /show-coverage-changed-info/compare?base=branchName\u0026target=branchName\n\n  定位代码修改所影响的 测试用例集, branchName 可以是 分支名，commit 或者 tag","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flust4life%2Fcoverage-diff-poc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flust4life%2Fcoverage-diff-poc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flust4life%2Fcoverage-diff-poc/lists"}