{"id":20200758,"url":"https://github.com/yifanzheng/spring-testing","last_synced_at":"2026-05-12T06:35:48.505Z","repository":{"id":108435955,"uuid":"323356808","full_name":"yifanzheng/spring-testing","owner":"yifanzheng","description":"Spring 单元测试与 mock","archived":false,"fork":false,"pushed_at":"2021-05-15T03:41:36.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T08:45:42.775Z","etag":null,"topics":["mock","mockito","spring-test"],"latest_commit_sha":null,"homepage":"","language":"Java","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/yifanzheng.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-12-21T14:18:18.000Z","updated_at":"2022-10-22T06:39:13.000Z","dependencies_parsed_at":"2023-04-11T17:02:36.371Z","dependency_job_id":null,"html_url":"https://github.com/yifanzheng/spring-testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yifanzheng/spring-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yifanzheng%2Fspring-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yifanzheng%2Fspring-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yifanzheng%2Fspring-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yifanzheng%2Fspring-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yifanzheng","download_url":"https://codeload.github.com/yifanzheng/spring-testing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yifanzheng%2Fspring-testing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32927622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-11T17:09:15.040Z","status":"online","status_checked_at":"2026-05-12T02:00:06.338Z","response_time":102,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["mock","mockito","spring-test"],"created_at":"2024-11-14T04:45:34.038Z","updated_at":"2026-05-12T06:35:48.501Z","avatar_url":"https://github.com/yifanzheng.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Spring Testing\n\n此项目包含 Spring 单元测试相关的内容。\n\n- [在 Spring 中使用 Mockito 进行单元测试](src/main/java/com/example/testing/mockito/README.md)\n\n- [在 Spring 中 Mock RestTemplate](src/main/java/com/example/testing/resttemplate/README.md)\n\n- [使用 PowerMock 模拟和测试私有方法](src/main/java/com/example/testing/privatemethod/README.md)\n\n## 测试框架介绍\n\nMockito 是一个单元测试模拟框架，可以让你写出优雅、简洁的单元测试代码。Mockito 采用了模拟技术，模拟了一些在应用中依赖的复杂对象，从而把测试对象和依赖对象隔离开来。\n\nPowerMock 是一个单元测试模拟框架，是在其它单元测试模拟框架的基础上做出扩展。通过提供定制的类加载器以及一些字节码篡改技术的应用，PowerMock 实现了对**静态方法、构造方法、私有方法以及 final 方法的模拟支持**等强大的功能。但是，正因为 PowerMock 进行了字节码篡改，导致部分单元测试用例并不被 JaCoco 统计覆盖率。\n\n所以，优先推荐使用 Mockito 提供的功能；只有在 Mockito 提供的功能不能满足需求时，才会采用 PowerMock 提供的功能；但是，不推荐使用影响 JaCoco 统计覆盖率的 PowerMock 功能。\n\n\n## 参考\n\n[1] [Mocking of Private Methods Using PowerMock](https://www.baeldung.com/powermock-private-method)  \n[2] [无所不能的PowerMock，mock私有方法，静态方法，测试私有方法，final类](https://www.cnblogs.com/ljw-bim/p/9391770.html)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyifanzheng%2Fspring-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyifanzheng%2Fspring-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyifanzheng%2Fspring-testing/lists"}