{"id":14989540,"url":"https://github.com/tommylemon/unitauto","last_synced_at":"2025-04-12T18:51:02.729Z","repository":{"id":37107378,"uuid":"234567250","full_name":"TommyLemon/UnitAuto","owner":"TommyLemon","description":"☀️ 最先进、最省事、ROI 最高的单元测试，机器学习 零代码、全方位、自动化 测试 方法/函数，用户包含腾讯、快手、某 500 强巨头等 ☀️ The most advanced unit testing way powered by machine learning. Coding-free, comprehensive and automatic testing for methods/functions. Used by Tencent, Kwai, a Fortune 500 company, etc.","archived":false,"fork":false,"pushed_at":"2025-01-12T15:54:25.000Z","size":31028,"stargazers_count":236,"open_issues_count":12,"forks_count":57,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T23:09:12.912Z","etag":null,"topics":["apiauto","apijson","golang","koa2","kotlin","mock","mocking","mocks","mockup","test-automation","testing-library","testing-tools","unit-test","unit-testing","unittest","unittest-library","unittesting","unittesting-library","vue2","vuejs2"],"latest_commit_sha":null,"homepage":"http://apijson.cn/unit","language":"JavaScript","has_issues":false,"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/TommyLemon.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-01-17T14:39:57.000Z","updated_at":"2025-04-02T02:29:57.000Z","dependencies_parsed_at":"2024-04-09T16:45:28.825Z","dependency_job_id":"27412976-da77-4f40-bba1-9884c7f5470d","html_url":"https://github.com/TommyLemon/UnitAuto","commit_stats":{"total_commits":432,"total_committers":4,"mean_commits":108.0,"dds":"0.17592592592592593","last_synced_commit":"7be646c1d297adeb279bc3baea693aab5ae16006"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TommyLemon%2FUnitAuto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TommyLemon%2FUnitAuto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TommyLemon%2FUnitAuto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TommyLemon%2FUnitAuto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TommyLemon","download_url":"https://codeload.github.com/TommyLemon/UnitAuto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618223,"owners_count":21134199,"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":["apiauto","apijson","golang","koa2","kotlin","mock","mocking","mocks","mockup","test-automation","testing-library","testing-tools","unit-test","unit-testing","unittest","unittest-library","unittesting","unittesting-library","vue2","vuejs2"],"created_at":"2024-09-24T14:18:32.025Z","updated_at":"2025-04-12T18:51:02.697Z","avatar_url":"https://github.com/TommyLemon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\" style=\"text-align:center;\"\u003e\n  UnitAuto\n\u003c/h1\u003e\n \n\u003cp align=\"center\"\u003e☀️ 机器学习零代码单元测试平台\u003c/p\u003e\n\u003cp align=\"center\"\u003e零代码、全方位、自动化 测试 方法/函数 的正确性、可用性和性能\u003c/p\u003e\n\u003cp align=\"center\" \u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java-Demo\"\u003e\u003cimg src=\"https://img.shields.io/badge/Java-1.8%2B-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java-Demo\"\u003e\u003cimg src=\"https://img.shields.io/badge/Kotlin-1.2%2B-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Go\"\u003e\u003cimg src=\"https://img.shields.io/badge/Go-1.18%2B-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Python\"\u003e\u003cimg src=\"https://img.shields.io/badge/Python-3.7%2B-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-CPP\"\u003e\u003cimg src=\"https://img.shields.io/badge/C%2B%2B-17%2B-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android\"\u003e\u003cimg src=\"https://img.shields.io/badge/Android-26%2B-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\" \u003e\n  \u003ca href=\"https://github.com/TommyLemon/UnitAuto#%E9%9B%86%E6%88%90%E5%88%B0%E8%A2%AB%E6%B5%8B%E9%A1%B9%E7%9B%AE\"\u003e使用文档\u003c/a\u003e\n  \u003ca href=\"https://search.bilibili.com/all?keyword=UnitAuto\"\u003e视频教程\u003c/a\u003e\n  \u003ca href=\"http://apijson.cn/unit\"\u003e在线体验\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" \u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/TommyLemon/UnitAuto/master/UnitAuto-Admin/img/logo.png\" /\u003e\n\u003c/p\u003e\n\n---\n\n机器学习零代码单元测试平台，零代码、全方位、自动化 测试 方法/函数 的正确性、可用性和性能。\u003cbr /\u003e\n用户包含 腾讯 IEG 互动娱乐事业群、腾讯 WXG 微信事业群、快手广告、某市值 4000亿+ 500 强巨头 等。\n\n已被 互联网教育智能技术及应用国家工程实验室 收录。\nhttps://github.com/TommyLemon/APIAuto/issues/19\n\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://user-images.githubusercontent.com/5738175/221088793-f60d1a43-fdb4-4cda-84ef-04fdee1aa472.png\"\u003e\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://raw.githubusercontent.com/TommyLemon/StaticResources/master/UnitAuto/UnitAuto-RandomTest-Parent-small.jpg\"\u003e\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://user-images.githubusercontent.com/5738175/224038704-fef31759-c349-40cb-a252-e0c8cff55110.png\"\u003e\n\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://github.com/TommyLemon/UnitAuto/assets/5738175/4c643a5a-b693-42a1-bb55-3eee61b97f2a\"\u003e\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://github.com/TommyLemon/UnitAuto/assets/5738175/12b2a81b-bc41-413c-b748-956bbdec7409\"\u003e\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://github.com/TommyLemon/UnitAuto/assets/5738175/842e1783-abc7-4cae-aaa5-f7693c69b4ce\"\u003e\n\n\n### 特点优势\n相比 JUnit, JTest, Mockito, Mockk 等一堆 Compiling testing 工具：\u003cbr /\u003e\n1.其它工具需要每个方法都写一大堆测试代码，需要开发成本、需要解决测试代码的 bug、业务代码更改后需要同步修改测试代码等；\u003cbr /\u003e\nUnitAuto 不需要写任何代码，直接读取方法的属性，自动注入参数，拿到返回值和类成员变量，机器学习自动化校验。\u003cbr /\u003e\n\u003cbr /\u003e\n2.UnitAuto 这种 Runtime testing 工具无需 Mock 环境(Application, Context 等)，\u003cbr /\u003e\n更不用为 无法有效地 Mock 环境相关类、第三方登录未提供 Mock 支持 等而头疼，\u003cbr /\u003e\n只要被测方法满足 有 return 值、有 interface 回调、改变成员变量 field 这 3 点中至少一点就能测。\n\n#### 腾讯内先后被 微信支付部门、IEG 工具开发组、CDG 金融支付组、IEG PC 游戏平台部 邀请分享了 \n* 零代码测试工具与实践(API•单元•UI)\n* 零代码开发和测试(API测试•单元测试•API开发)\n* 零代码开发和测试(API测试•单元测试•API开发)\n* 零代码开发和测试(接口测试•单元测试•接口开发)\n\n#### 质效无双线上技术访谈-零代码智能测试工具实践介绍-第11期\nhttps://testwo.cn1.quickconnect.cn/vs/sharing/iiP8VK1C#!aG9tZV92aWRlby0xMQ==\n![https://testwo.cn1.quickconnect.cn/vs/sharing/iiP8VK1C#!aG9tZV92aWRlby0xMQ==](https://user-images.githubusercontent.com/5738175/179578082-0c72a715-c9b3-49f7-bf1c-45f963c6eb4f.png)\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### 原理说明\n被测项目不需要写任何单元测试代码（逻辑代码、注解代码等全都不要），\u003cbr /\u003e\nUnitAuto 会自动生成测试参数，并执行方法，拿到返回值等进行校验。\u003cbr /\u003e\n泛型、接口等自动模拟，异步执行方法自动记录回调过程，都是零代码。\u003cbr /\u003e\n\u003cbr /\u003e\n[UnitAuto-Admin](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Admin) 是类似 [APIAuto](https://github.com/TommyLemon/APIAuto) 的机器学习零代码测试工具（查看、上传、执行、测试 后端项目中的方法等），\u003cbr /\u003e\n[UnitAuto-Java](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java) 提供扫描所有方法、执行某个方法两个 API （主要引入 [MethodUtil.java](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java/src/main/java/unitauto/MethodUtil.java) 这个类，里面已实现）。\u003cbr /\u003e\n\u003cbr /\u003e\n\n##### 通过扫描项目中的可访问的 package, class, method 来生成和导入测试用例  \n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://raw.githubusercontent.com/TommyLemon/StaticResources/master/UnitAuto/UnitAuto-Method-List-small.jpg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\n##### HTTP 远程调用被测服务/App，转至内部 构造/获取 实例来 invoke 动态执行方法\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://user-images.githubusercontent.com/5738175/87251324-6b759900-c49d-11ea-8468-aaf26124b7e0.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\n##### 获取参数、成员变量等前后状态，拦截方法被调用过程并可视化展示\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://raw.githubusercontent.com/TommyLemon/StaticResources/master/UnitAuto/UnitAuto-Test-interface-small.jpg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\n##### 通过简单配置自动调整参数组合，拿到返回结果后通过 前后结果对比 或 机器学习校验模型 来自动断言\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://raw.githubusercontent.com/TommyLemon/StaticResources/master/UnitAuto/UnitAuto-RandomTest-Parent-small.jpg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://raw.githubusercontent.com/TommyLemon/StaticResources/master/UnitAuto/UnitAuto-RandomTest-Child-small.jpg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\n##### 后端不再需要像以下示例一样编写和维护大量单元测试用例代码（逻辑代码、注解代码等）：\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://raw.githubusercontent.com/TommyLemon/StaticResources/master/UnitAuto/UnitAuto-Compare-Code-small.jpg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\n##### 客户端可作为 HTTP Server 来为 UnitAuto 网页工具 提供远程调用的接口，效果同样：\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://user-images.githubusercontent.com/5738175/87251324-6b759900-c49d-11ea-8468-aaf26124b7e0.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\" \u003e\n  \u003ca \u003e\u003cimg src=\"https://user-images.githubusercontent.com/5738175/87251395-f5bdfd00-c49d-11ea-809f-3c7330d7b6e1.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### 示例项目\n[UnitAuto Java 后端 Server](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java-Demo)    在线 [测试](http://apijson.cn:8081) \u003cbr /\u003e\n[APIJSON Java 后端 Server](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot)    在线 [测试](http://apijson.cn/unit/) \u003cbr /\u003e\n[UnitAuto Android 客户端 App](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android)    直接 [下载](https://github.com/TommyLemon/UnitAuto/releases/download/2.6.0/UnitAutoApp.apk) （第一次可能失败，返回报错 JSON，一般重试一次就可以）\u003cbr /\u003e\n[APIJSON Android 客户端 App](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Android/APIJSONTest)    直接 [下载](https://github.com/TommyLemon/UnitAuto/releases/download/2.5.0/APIJSONTest.apk) （第一次可能失败，返回报错 JSON，一般重试一次就可以）\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### 演讲视频\nUnitAuto-机器学习自动化单元测试平台简介 \u003cbr /\u003e\nhttps://www.bilibili.com/video/BV1Tk4y1R7Yo\n\u003cbr /\u003e\n\u003cbr /\u003e\nUnitAuto-异步回调方法的零代码单元测试 \u003cbr /\u003e\nhttps://www.bilibili.com/video/BV1kk4y1z7bW\n\u003cbr /\u003e\n\n其它\nhttps://search.bilibili.com/all?keyword=UnitAuto\n\u003cbr /\u003e\n\n### 集成到被测项目\n#### Java 后端 Server\n##### 1.依赖 unitauto.jar \n放到你 [启动 Application 所在项目的 libs 目录](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java-Demo/libs)，然后 Eclipse Add to Build Path 或 Idea Add as Library \u003cbr /\u003e\nhttps://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java-Demo/libs \u003cbr /\u003e\n\u003cbr /\u003e\n\n##### 2.依赖 unitauto-jar.jar\n如果不打 jar/war 包，则可以跳过这个步骤。\u003cbr /\u003e\n依赖方式同步骤 1。\u003cbr /\u003e\nhttps://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Java-Demo/libs \u003cbr /\u003e\n依赖后需要在 [Application static 代码块](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java-Demo/src/main/java/unitauto/demo/DemoApplication.java) 中初始化\n```java\n    static {\n        UnitAutoApp.init();\n    }\n```\n\u003cbr /\u003e\n\n##### 3.提供接口给 UnitAuto 后台管理工具\nController 提供两个 POST application/json 格式的 HTTP API，分别是\n```\n/method/list    动态扫描方法，可以单纯接收入参并转发到 MethodUtil.listMethod(String request)\n/method/invoke  动态执行方法，可以单纯接收入参并转发到 MethodUtil.invokeMethod(String request, Object instance, Listener\u003cJSONObject\u003e listener)\n```\n参考 [DemoController](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java-Demo/src/main/java/unitauto/demo/controller/DemoController.java) \u003cbr /\u003e\n\u003cbr /\u003e\n\n##### 4.配置环境相关类及自定义处理逻辑\n拦截 [MethodUtil](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java/src/main/java/unitauto/MethodUtil.java) 类中的 INSTANCE_GETTER, JSON_CALLBACK, CLASS_LOADER_CALLBACK 等 interface 的回调方法，\u003cbr /\u003e\n可以支持获取 Context 等环境相关类的实例、转 JSON 对象时过滤特定类、其它自定义逻辑处理，参考 [DemoApplication](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java-Demo/src/main/java/unitauto/demo/DemoApplication.java)\u003cbr /\u003e\n\u003cbr /\u003e\u003cbr /\u003e\n\n#### Android 客户端 App\n##### 1.依赖 UnitAuto-Apk\n把 [UnitAuto-Apk](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android/UnitAuto-Apk) 导入到你项目 [app moudule 所在目录](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android)，[settings.gradle](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android/settings.gradle) 中\n```groovy\ninclude ':UnitAuto-Apk'\n```\n[app moudule 目录](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android/app)，[build.gradle](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Android/app/build.gradle) 中\n```groovy\ndependencies {\n    api project(':UnitAuto-Apk')\n}\n```\n\u003cbr /\u003e\n\n##### 2.初始化 UnitAuto\n在 [Application onCreate 方法](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/app/src/main/java/unitauto/demo/DemoApp.java) 中初始化\n```java\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        UnitAutoApp.init(this);\n    }\n```\n\u003cbr /\u003e\n\n##### 3.提供 UnitAuto 管理界面入口\n在 [AndroidManifest.xml](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/app/src/main/AndroidManifest.xml) 中注册 [UnitAutoActivity](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/UnitAuto-Apk/src/main/java/unitauto/apk/UnitAutoActivity.java)\n```xml\n\u003cmanifest ... \u003e\n    \u003capplication ... \u003e\n      \n        \u003cactivity\n            android:name=\"unitauto.apk.UnitAutoActivity\"\n            android:launchMode=\"singleInstance\"\u003e\n        \u003c/activity\u003e\n      \n     \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\n可在你项目的任何界面新增一个按钮或其它形式的入口，仅 DEBUG 模式下展示\n```xml\n    \u003cButton\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:onClick=\"onClickUnit\"\n        android:text=\"UnitAutoActivity\"\n        android:textAllCaps=\"false\"\n        /\u003e\n```\n参考 [layout/activity_main](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/app/src/main/res/layout/activity_main.xml) \u003cbr /\u003e\n\u003cbr /\u003e\n点击这个入口跳转到 [UnitAutoActivity](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/UnitAuto-Apk/src/main/java/unitauto/apk/UnitAutoActivity.java)\n```java\n    public void onClickUnit(View v) {\n        startActivity(UnitAutoActivity.createIntent(this));\n    }\n```\n参考 [MainActivity](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/app/src/main/java/unitauto/demo/MainActivity.java) \u003cbr /\u003e\n\u003cbr /\u003e\n\n##### 4.配置环境相关类及自定义处理逻辑\n在 [Application onCreate 方法](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Android/app/src/main/java/unitauto/demo/DemoApp.java) 中配置，参考 [Java 后端 Server 中 4.配置环境相关类及自定义处理逻辑](https://github.com/TommyLemon/UnitAuto#4%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E7%9B%B8%E5%85%B3%E7%B1%BB%E5%8F%8A%E8%87%AA%E5%AE%9A%E4%B9%89%E5%A4%84%E7%90%86%E9%80%BB%E8%BE%91)\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### 部署后台管理工具\n可以直接[下载源码](https://github.com/TommyLemon/UnitAuto/archive/master.zip)解压后用浏览器打开 [UnitAuto-Admin](https://github.com/TommyLemon/UnitAuto/tree/master/UnitAuto-Admin)/index.html，建议用 Chrome 或 火狐 (Safari、Edge、IE 等可能有兼容问题)。\u003cbr /\u003e\n也可以直接访问官网的环境 http://apijson.cn/unit 或 http://apijson.cn:8081 \u003cbr /\u003e\n\u003cbr /\u003e\n点右上角设置项 \"项目服务器地址 URL\"，把输入框内基地址改为你主机的地址(例如 http://192.168.0.102:8080 )\u003cbr /\u003e\n\u003cbr /\u003e\n右上角登录的默认管理员账号为 13000082001 密码为 123456，\u003cbr /\u003e\n\u003cbr /\u003e\n然后点右上角设置项 \"查看、同步方法文档\"，确保被测项目已启动，然后一键导入项目中的方法。\n\u003cbr /\u003e\n等它完成后自动显示测试用例列表，点击列表项进去查看详情和手动测试，或者一键自动回归测试全部 方法/函数。\n\u003cbr /\u003e\n\n如果测试 Android/iOS App，需要保证 手机/平板 与 使用 UnitAuto-Admin 网页的电脑 连接同一个局域网，\u003cbr /\u003e\n如果使用 Android/iOS 模拟器，则一定都是在同一个局域网，并且可以用 http://localhost:端口 进行访问。\u003cbr /\u003e\n![](https://user-images.githubusercontent.com/5738175/87251395-f5bdfd00-c49d-11ea-809f-3c7330d7b6e1.png)\n\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cbr /\u003e\n自动管理测试用例 这个功能 需要部署 APIJSONBoot ，见 \u003cbr /\u003e \nhttps://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### 新增测试用例\n可以使用以下几种方式：\n#### 1.远程扫描方法\nhttps://github.com/TommyLemon/UnitAuto/blob/master/README.md#%E8%BF%9C%E7%A8%8B%E6%89%AB%E6%8F%8F%E6%96%B9%E6%B3%95\n\n#### 2.调用 /delegate 代理接口来录制请求的方法、参数、响应等信息\nhttps://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONBoot-MultiDataSource#%E4%BB%A3%E7%90%86%E6%8E%A5%E5%8F%A3%E5%8F%8A%E5%BD%95%E5%88%B6%E6%B5%81%E9%87%8F\n\n#### 3.打开分享链接来自动填充 方法 URI、参数 JSON、请求头、参数注入配置、设置项 等\n例如：\nhttp://apijson.cn/unit/?send=true\u0026type=JSON\u0026url=unitauto.test.TestUtil.minus\u0026json={%22static%22:true,%22methodArgs%22:[{%22type%22:%22long%22,%22value%22:1},{%22type%22:%22long%22,%22value%22:2}]}\n\n#### 4.在界面手动填写 方法 URI、参数 JSON 等再点击上传/分享按钮\n可点击分享按钮生成分享链接，用浏览器打开即可自动填充。\n\n\u003cbr /\u003e\n\n### 远程扫描方法\nUnitAuto-Admin 登录后点击 设置项 \\[查看、同步方法文档]，等返回方法属性 JSON 后点 \\[上传] 按钮\n![image](https://user-images.githubusercontent.com/5738175/172366167-87b5de56-16c0-4a44-bed7-6a6fe76a4209.png)\n\n对应发送 HTTP 请求 \u003cbr /\u003e\n[POST /method/list](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-SpringBoot-SDK/src/main/java/unitauto/boot/UnitAutoController.java#L43-L50)\n```js\n{\n    \"query\": 2,  // 0-数据，1-总数，2-全部\n    \"mock\": true,\n    \"package\": \"unitauto.test\",\n    \"class\": \"TestUtil\",\n    \"method\": \"divide\",\n    \"types\": null\n}\n```\n\n详细说明见 MethodUtil.listMethod 的注释 \u003cbr /\u003e\nhttps://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java/src/main/java/unitauto/MethodUtil.java#L287-L300\n\n\u003cbr /\u003e\n\n### 远程调用方法\nUnitAuto-Admin 点击 \\[运行方法]\n![image](https://user-images.githubusercontent.com/5738175/172368105-d4d0b53c-59a7-42d8-aaf1-4ecfc0711b8a.png)\n\n同步方法 \u003cbr /\u003e\nunitauto.test.TestUtil.divide\n```js\n{\n    \"static\": true,\n    \"methodArgs\": [\n        {   // 可省略来自动判断的 type : Boolean,Integer,BigDecimal,String,Object,JSONArray 这几种 JSON 类型\n            \"type\": \"double\",\n            \"value\": 1\n        },\n        {   // 支持各种类型，例如 unitauto.demo.domain.User, List\u003cString\u003e, annotation.Annotation[]，未注册的要写完整全路径\n            \"type\": \"double\",\n            \"value\": 2\n        }\n    ]\n}\n```\n\n也可以简化为 \n```js\n{\n    \"static\": true,\n    \"methodArgs\": [\n        \"double:1\",\n        \"double:2\"  // 如果是 JSON 类型，可以不写类型只写值，例如 true, 1, 3.14, \"ok\", {\"a\": 1}, [1, 2, 3]\n    ]\n}\n```\n\n对应发送 HTTP 请求  \u003cbr /\u003e\n[POST /method/invoke](https://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-SpringBoot-SDK/src/main/java/unitauto/boot/UnitAutoController.java#L52-L102)\n```js\n{\n    \"package\": \"unitauto.test\",\n    \"class\": \"TestUtil\",\n    \"method\": \"divide\",\n    \"static\": true,\n    \"methodArgs\": [\n        {\n            \"type\": \"double\",\n            \"value\": 1\n        },\n        {\n            \"type\": \"double\",\n            \"value\": 2\n        }\n    ]\n}\n```\n\n\n对应调用 Java 方法  \u003cbr /\u003e\nunitauto.test.TestUtil.divide(double, double)\n```java\n    public static double divide(double a, double b) {\n        return a / b;\n    }\n```\nhttps://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java/src/main/java/unitauto/test/TestUtil.java#L56-L58\n\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://user-images.githubusercontent.com/5738175/224038704-fef31759-c349-40cb-a252-e0c8cff55110.png\"\u003e\n\n异步回调方法  \u003cbr /\u003e\nunitauto.test.TestUtil.computeAsync\n```js\n{\n    \"static\": true,\n    \"methodArgs\": [\n        \"long:8\",\n        \"long:2\",\n        {\n            \"type\": \"unitauto.test.TestUtil$Callback\",\n            \"value\": {\n                \"sort()\": { // 可以简写为 \"sort()\": false \n                    \"type\": \"Boolean\",\n                    \"return\": false\n                },\n                \"setData(D)\": {\n                    \"callback\": true\n                }\n            }\n        }\n    ]\n}\n```\n\n\n对应调用 Java 方法  \u003cbr /\u003e\nunitauto.test.TestUtil.computeAsync(long, long, Callback)\n```java\n\tpublic static Number computeAsync(long a, long b, Callback callback) {\n\n\t\tnew Thread(new Runnable() {\n\n\t\t\t@Override\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tThread.sleep(3000);\n\t\t\t\t} catch (Exception e) {}\n\t\t\t\t\n\t\t\t\tBoolean sort = callback.sort();\n\t\t\t\tif (sort != null \u0026\u0026 sort \u0026\u0026 a \u003e b) {\n\t\t\t\t\tcallback.minusAsId(b, a);\n\t\t\t\t} else {\n\t\t\t\t\tcallback.minusAsId(a, b);\n\t\t\t\t}\n\n\t\t\t\tcallback.setData(\"Mock inner interface success!\");\n\t\t\t}\n\t\t}).start();\n\n\t\treturn callback.getId();\n\t}\n```\nhttps://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java/src/main/java/unitauto/test/TestUtil.java#L95-L117\n\n \u003cbr /\u003e \u003cbr /\u003e\n\n详细说明见 MethodUtil.invokeMethod 的注释 \u003cbr /\u003e\nhttps://github.com/TommyLemon/UnitAuto/blob/master/UnitAuto-Java/src/main/java/unitauto/MethodUtil.java#L353-L424\n\n\u003cbr /\u003e\n\n### 后台 Headless 无 UI 模式回归测试\nJenkins、蓝盾 等 CI/CD 等流水线不支持带 UI 测试，所以提供了这个模式， \u003cbr /\u003e\n通过调用 HTTP API 即可执行用例和查看进度，方便集成到 CI/CD 流水线。\n![image](https://user-images.githubusercontent.com/5738175/199445916-29ac8ded-8838-46d8-88ff-0daad06b11a9.png)\n![image](https://user-images.githubusercontent.com/5738175/199445960-2eac952e-75d9-48b1-945b-5759370c21c0.png)\n\n#### 1.配置 Node 环境及 NPM 包管理工具\nhttps://nodejs.org\n\n#### 2.安装相关依赖\nhttps://koajs.com\n```sh\nnvm install 7\nnpm i koa\n```\n\n#### 3.使用后台 HTTP 服务\n先启动 HTTP 服务\n```sh\ncd js\nnode server.js\n```\n如果运行报错 missing package xxx，说明缺少相关依赖，参考步骤 2 来执行\n```sh\nnpm i xxx\n```\n然后再启动 HTTP 服务。\u003cbr /\u003e\n\n启动成功后会有提示，点击链接或者复制到浏览器输入框打开即可。\u003cbr /\u003e\u003cbr /\u003e\n如果托管服务是用 [APIJSONBoot-MultiDataSource](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONBoot-MultiDataSource) 部署的，\u003cbr /\u003e\n链接 host 后可以加上 /unit，例如 http://localhost:3001/unit/test/start \u003cbr /\u003e\n通过这个接口来放宽前端执行时查询测试用例、参数配置等列表的条数，一次可批量执行更多用例。\n\n\u003cbr /\u003e\n\n### 统计覆盖率\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://github.com/TommyLemon/UnitAuto/assets/5738175/e3e54fd5-9a42-4a26-a58d-853168fe0682\"\u003e\n\n\n#### 1.点右侧 Maven \u003e Lifecycle \u003e package 或 运行以下命令 来把项目打成 jar 包：\n```sh\nmvn clean package\n```\n完成后 target 目录应该有 unitauto-java-demo.jar(springboot-maven-plugin 重新打包) 和 unitauto-java-demo.jar.original(maven 直接打包) 这样的两个 jar 包\n\n#### 2.使用 JaCoCo Agent 作为 Java Agent 来运行 jar 包\n```sh\njava -javaagent:libs/jacocoagent.jar=destfile=../jacoco.exec,includes=*,output=tcpserver,port=6300,address=127.0.0.1 -jar target/unitauto-java-demo-2.9.0.jar\n```\n\n#### 3.点右侧 Maven \u003e Plugins \u003e jacoco \u003e jacoco:dump \u003e jacoco:report 或 运行以下命令 来导出覆盖率数据和生成查看报告的 HTML 网页\n```sh\njacoco dump\njacoco report \n```\n完成后 target 目录应该有 jacoco.exec(覆盖率数据) 和 site/jacoco 目录且里面有 index.html 网页入口文件、jacoco-resources 资源文件夹 等。 \u003cbr /\u003e\n用 Chrome/Firefox 浏览器打开 index.html，可以看到覆盖率报告。\n\n\u003cimg width=\"1495\" alt=\"image\" src=\"https://github.com/TommyLemon/UnitAuto/assets/5738175/4c643a5a-b693-42a1-bb55-3eee61b97f2a\"\u003e\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n### 常见问题\n#### 1.无法访问接口\nChrome 90+ 对 CORS 请求禁止携带 Cookie 或 Chrome 80-89 强制 same-site Cookie 的策略导致 \u003cbr /\u003e\nhttps://github.com/TommyLemon/UnitAuto/issues/11\n\n#### 2.没有生成文档\n右上角设置项与数据库实际配置不一致 等  \u003cbr /\u003e\nhttps://github.com/Tencent/APIJSON/issues/85\n\n#### 3.托管服务器访问不了\n不能代理接口、不能展示文档、不能对断言结果纠错 等 \u003cbr /\u003e\nhttps://github.com/TommyLemon/APIAuto/issues/12\n  \n#### 4.apijson.cn 访问不了\n托管服务地址改为 http://47.98.196.224:8080  \u003cbr /\u003e\nhttps://github.com/TommyLemon/APIAuto/issues/13\n \n#### 5.如何统计行覆盖率/分支覆盖率？\n##### Java/Kotlin 可以用 Jacoco(on-the-fly 运行时动态插桩模式)\nhttps://www.jacoco.org/jacoco/trunk/doc/agent.html  \u003cbr /\u003e\nhttps://www.jacoco.org/jacoco/trunk/doc/cli.html  \u003cbr /\u003e\n\u003cbr /\u003e\n还可以搜索并参考 \"JaCoCo\" 相关文章，例如：  \u003cbr /\u003e\nJava 覆盖率 Jacoco 插桩的不同形式总结和踩坑记录  \u003cbr /\u003e\nhttps://testerhome.com/topics/20632\n\n##### Go 可以用 goc 或 gcov \n我们是如何做go语言系统测试覆盖率收集的？  \u003cbr /\u003e\nhttps://zhuanlan.zhihu.com/p/149890900  \u003cbr /\u003e\n  \nGcov 查看代码覆盖率  \u003cbr /\u003e\nhttps://zhuanlan.zhihu.com/p/410077415\n\n##### Python 可以使用 coverage\n\nPython单元测试框架覆盖率-Coverage  \u003cbr /\u003e\nhttps://cloud.tencent.com/developer/article/1513269\n\n##### C++ 可以用 gcov + lcov \nhttps://cloud.tencent.com/developer/news/1309383\n\n\u003cbr /\u003e\n  \n更多常见问题 \u003cbr /\u003e\nhttps://github.com/TommyLemon/APIAuto/issues\n\n\u003cbr /\u003e\n\n### 感谢开源\n* jsonon\n* editor.md\n* vue.js\n\n### 技术交流\n##### 关于作者\n[https://github.com/TommyLemon](https://github.com/TommyLemon)\u003cbr /\u003e\n\u003cimg width=\"1280\" src=\"https://github.com/TommyLemon/UIGO/assets/5738175/ec77df98-ff9b-43aa-b2f1-2fce2549d276\"\u003e\n\n如果有什么问题或建议可以 [去 APIAuto 提 issue](https://github.com/TommyLemon/APIAuto/issues)，交流技术，分享经验。\u003cbr \u003e\n如果你解决了某些 bug，或者新增了一些功能，欢迎 [提 PR 贡献代码](https://github.com/Tencent/APIJSON/blob/master/CONTRIBUTING.md)，感激不尽。\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### 其它项目\n\n[APIJSON](https://github.com/Tencent/APIJSON) 🚀 腾讯零代码、全功能、强安全 ORM 库 🏆 后端接口和文档零代码，前端(客户端) 定制返回 JSON 的数据和结构\n\n[APIAuto](https://github.com/TommyLemon/APIAuto) 敏捷开发最强大易用的 HTTP 接口工具，机器学习零代码测试、生成代码与静态检查、生成文档与光标悬浮注释，集 文档、测试、Mock、调试、管理 于一体的一站式体验\n\n[SQLAuto](https://github.com/TommyLemon/SQLAuto) 智能零代码自动化测试 SQL 语句执行结果的数据库工具，任意增删改查、任意 SQL 模板变量、一键批量生成参数组合、快速构造大量测试数据\n\n[UIGO](https://github.com/TommyLemon/UIGO) 📱 零代码快准稳 UI 智能录制回放平台 🚀 自动兼容任意宽高比分辨率屏幕，自动精准等待网络请求，录制回放快、准、稳！\n\n[apijson-doc](https://github.com/vincentCheng/apijson-doc) APIJSON 官方文档，提供排版清晰、搜索方便的文档内容展示，包括设计规范、图文教程等\n\n[APIJSONdocs](https://github.com/ruoranw/APIJSONdocs) APIJSON 英文文档，提供排版清晰的文档内容展示，包括详细介绍、设计规范、使用方式等\n\n[apijson.org](https://github.com/APIJSON/apijson.org) APIJSON 官方网站，提供 APIJSON 的 功能简介、登记用户、作者与贡献者、相关链接 等\n\n[APIJSON.NET](https://github.com/liaozb/APIJSON.NET) C# 版 APIJSON ，支持 MySQL, PostgreSQL, SQL Server, Oracle, SQLite\n\n[apijson-go](https://github.com/glennliao/apijson-go) Go 版 APIJSON ， 基于Go(\u003e=1.18) + GoFrame2, 支持查询、单表增删改、权限管理等\n  \n[apijson-go](https://gitee.com/tiangao/apijson-go) Go 版 APIJSON ，支持单表查询、数组查询、多表一对一关联查询、多表一对多关联查询 等\n\n[apijson-hyperf](https://github.com/kvnZero/hyperf-APIJSON.git) PHP 版 APIJSON，基于 Hyperf 支持 MySQL\n\n[APIJSON-php](https://github.com/xianglong111/APIJSON-php) PHP 版 APIJSON，基于 ThinkPHP，支持 MySQL, PostgreSQL, SQL Server, Oracle 等\n\n[apijson-php](https://github.com/qq547057827/apijson-php) PHP 版 APIJSON，基于 ThinkPHP，支持 MySQL, PostgreSQL, SQL Server, Oracle 等\n\n[apijson-node](https://github.com/kevinaskin/apijson-node) 字节跳动工程师开源的 Node.ts 版 APIJSON，提供 nestjs 和 typeorm 的 Demo 及后台管理\n\n[uliweb-apijson](https://github.com/zhangchunlin/uliweb-apijson) Python 版 APIJSON，支持 MySQL, PostgreSQL, SQL Server, Oracle, SQLite 等\n\n[apijson-practice](https://github.com/vcoolwind/apijson-practice) BAT 技术专家开源的 APIJSON 参数校验注解 Library 及相关 Demo\n\n[Android-ZBLibrary](https://github.com/TommyLemon/Android-ZBLibrary) Android MVP 快速开发框架，Demo 全面，注释详细，使用简单，代码严谨\n\n\n### 持续更新\n[https://github.com/TommyLemon/UnitAuto/commits/master](https://github.com/TommyLemon/UnitAuto/commits/master)\n\n### 我要赞赏\n创作不易、坚持更难，右上角点亮 ⭐ Star 支持下本项目吧，谢谢 ^_^ \u003cbr /\u003e\n[https://gitee.com/TommyLemon/UnitAuto](https://gitee.com/TommyLemon/UnitAuto)\n\u003cbr /\u003e\n\u003cbr /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftommylemon%2Funitauto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftommylemon%2Funitauto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftommylemon%2Funitauto/lists"}