{"id":17543591,"url":"https://github.com/wesleyone/case-test","last_synced_at":"2025-03-29T05:34:04.101Z","repository":{"id":57735185,"uuid":"332505036","full_name":"WesleyOne/case-test","owner":"WesleyOne","description":"easy testing for cases","archived":false,"fork":false,"pushed_at":"2021-02-10T06:49:39.000Z","size":125,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T15:55:39.451Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WesleyOne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-24T17:01:41.000Z","updated_at":"2024-06-07T10:03:42.000Z","dependencies_parsed_at":"2022-09-14T13:20:28.395Z","dependency_job_id":null,"html_url":"https://github.com/WesleyOne/case-test","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyOne%2Fcase-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyOne%2Fcase-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyOne%2Fcase-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyOne%2Fcase-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WesleyOne","download_url":"https://codeload.github.com/WesleyOne/case-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246145013,"owners_count":20730494,"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":[],"created_at":"2024-10-21T00:24:56.498Z","updated_at":"2025-03-29T05:34:04.079Z","avatar_url":"https://github.com/WesleyOne.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 项目介绍\ncase-test\n\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.wesleyone/case-test)](https://search.maven.org/artifact/io.github.wesleyone/case-test/2.0/jar)\n\n### 背景\n在做定价接口的逻辑调整时，发现测试用例非常多（用户角色、活动、营销等多维度聚合），用例预期结果具有大量重复，逐个写单测代码量巨大且效率低。\n\n### 功能\n针对单一功能、大量业务场景的接口，通过**自动封装入参对象**，将相同结果的入参对象**聚合到同一场景**中来处理，简化测试代码量（主要是重复封装入参对象和同样的冒烟断言等代码），提高开发效率。\n\n## 框架介绍\n### 概念\n- 入参对象: 业务接口的入参对象；\n- 属性值对象：入参对象有多个属性，每个属性有多种值，属性值对象用来维护某个属性的所有值；\n- 场景：具有业务上相同结果的入参对象集合；\n\n### 核心\n- 自动封装入参对象\n- 聚合到同一场景来处理\n\n### 示意图\n\n![示意图](./casetest.jpg)\n\n## 使用介绍\n\n#### 1. 添加maven依赖\n```xml\n\u003c!-- https://mvnrepository.com/artifact/io.github.wesleyone/case-test --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.wesleyone\u003c/groupId\u003e\n    \u003cartifactId\u003ecase-test\u003c/artifactId\u003e\n    \u003cversion\u003e2.0\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n#### 2. 构建**属性值对象**\n\n参考在本项目中的如下测试代码：\n\n`io.github.wesleyone.cases.test.GoodInfoParam`\n`io.github.wesleyone.cases.test.IsNewUserParam`\n   \n将相应接口入参对象需要用到的属性分别新建**属性值对象**\n - 实现`io.github.wesleyone.cases.test.IParam`接口 \n - 通过方法形式构建对应的属性值\n\n#### 3. 实现测试启动类\n\n参考在本项目中的如下测试代码：\n\n`io.github.wesleyone.cases.test.PriceContextTestBoostrap`\n\n新建启动类实现`io.github.wesleyone.cases.test.TestBootstrap`，继承`io.github.wesleyone.cases.test.TestBootstrap`类，并实现`newBizContext`、`setProperties`、`handle`自定义方法\n`newBizContext`方法：实例业务上下文对象\n`setProperties`方法：自定义设置属性\n`handle`方法：自定义接口方法处理\n\n#### 4. 构建场景方法\n\n参考在本项目中的如下测试代码：\n\n`io.github.wesleyone.cases.test.PriceContextTestBoostrap`\n\n实现**前置方法**、**后置方法**\n\n```java\npublic class PriceContextTestBoostrap extends TestBootstrap\u003cPriceContext\u003e {\n    \n    /**\n     * 前置处理方法，可以没有\n     * 命名要求如下：\n     * before_{对应后置处理方法}\n     *\n     * @param context 场景上下文\n     */\n    public void before_newUserAllGoods(TestCaseContext\u003cPriceContext\u003e context) {\n        System.out.println(\"newUserAllGoods前置处理，可以在此处初始化MOCK数据等\");\n    }\n\n    /**\n     * 后置处理方法\n     * 注解部分指定入参的属性范围\n     * 方法内容实现具体的后置处理\n     *\n     * @param context 场景上下文\n     */\n    @TestCase(name = \"新用户购买所有商品\", desc = \"使用新人价\",params = {\n            @TestParam(clazz = IsNewUserParam.class, in = \"newUser\"),\n            @TestParam(clazz = GoodInfoParam.class),\n    })\n    public void newUserAllGoods(TestCaseContext\u003cPriceContext\u003e context) {\n        System.out.println(\"newUserAllGoods后置处理，可以在此处断言校验等\");\n    }\n}\n```\n\n#### 5. 开始执行\n\n添加测试入口方法如下，其中`run()`方法是`TestBootstrap`父类的启动方法\n```\n    @Test\n    public void test() {\n        run();\n    }\n```\n运行该测试入口方法，则会将当前类的所有场景跑一边。\n\n\u003e 建议将场景方法按业务场景分开到多个类，然后这些类共同继承上文的测试启动类。\n\n\n## 缺陷\n1. 属性值对象不支持MAP属性（业务接口入参属性原则上不允许MAP类型）\n2. 其他缺陷\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwesleyone%2Fcase-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwesleyone%2Fcase-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwesleyone%2Fcase-test/lists"}