kcode-pi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +358 -0
- package/dist/cli/kcode.d.ts +15 -0
- package/dist/cli/kcode.js +153 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +7 -0
- package/docs/KCODE_DISTRIBUTION.md +91 -0
- package/extensions/kingdee-harness.ts +180 -0
- package/extensions/kingdee-header.ts +122 -0
- package/extensions/kingdee-tools.ts +379 -0
- package/knowledge/.backup/v1.0.0/version.json +10 -0
- package/knowledge/cangqiong/product-notes.md +15 -0
- package/knowledge/common/business-flows.md +115 -0
- package/knowledge/common/config-guides.md +110 -0
- package/knowledge/common/error-patterns.md +170 -0
- package/knowledge/common/implementation.md +144 -0
- package/knowledge/cosmic/hard-constraints.md +38 -0
- package/knowledge/cosmic/ksql-datafix.md +34 -0
- package/knowledge/cosmic/platform-baseline.md +32 -0
- package/knowledge/cosmic/plugin-decision-matrix.md +40 -0
- package/knowledge/cosmic/review-checklist.md +40 -0
- package/knowledge/cosmic/unittest.md +35 -0
- package/knowledge/enterprise/api-reference.md +186 -0
- package/knowledge/enterprise/code-patterns.md +217 -0
- package/knowledge/enterprise/plugin-lifecycle.md +188 -0
- package/knowledge/enterprise/tables.json +159 -0
- package/knowledge/flagship/api-reference.md +237 -0
- package/knowledge/flagship/code-patterns.md +246 -0
- package/knowledge/flagship/cosmic-platform-note.md +15 -0
- package/knowledge/flagship/plugin-lifecycle.md +248 -0
- package/knowledge/flagship/tables.json +159 -0
- package/knowledge/version.json +10 -0
- package/knowledge/xinghan/product-notes.md +15 -0
- package/package.json +71 -0
- package/prompts/kd-discuss.md +11 -0
- package/prompts/kd-execute.md +12 -0
- package/prompts/kd-plan.md +12 -0
- package/prompts/kd-ship.md +12 -0
- package/prompts/kd-spec.md +12 -0
- package/prompts/kd-verify.md +12 -0
- package/skills/kd-check/SKILL.md +26 -0
- package/skills/kd-cosmic-dev/SKILL.md +82 -0
- package/skills/kd-cosmic-review/SKILL.md +90 -0
- package/skills/kd-cosmic-unittest/SKILL.md +92 -0
- package/skills/kd-debug/SKILL.md +30 -0
- package/skills/kd-discuss/SKILL.md +24 -0
- package/skills/kd-execute/SKILL.md +22 -0
- package/skills/kd-gen/SKILL.md +34 -0
- package/skills/kd-ksql/SKILL.md +86 -0
- package/skills/kd-plan/SKILL.md +24 -0
- package/skills/kd-ship/SKILL.md +22 -0
- package/skills/kd-spec/SKILL.md +24 -0
- package/skills/kd-verify/SKILL.md +22 -0
- package/themes/kcode-dark.json +81 -0
- package/vendor/kingdee-skills/cosmic-unittest/SKILL.md +788 -0
- package/vendor/kingdee-skills/cosmic-unittest/author-cache.json +5 -0
- package/vendor/kingdee-skills/cosmic-unittest/cosmic-unittest-skill-overview.html +746 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/business-test.md +205 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/common-test.md +257 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/formplugin-test.md +560 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/op-plugin-test.md +231 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/validator-test.md +232 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/business-helper.md +184 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/common-module.md +355 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/convert-plugin.md +130 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/formplugin.md +235 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/op-plugin.md +226 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/validator.md +206 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +674 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md +307 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md +129 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/coding-standard-checklist.md +491 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/cosmic-api-checklist.md +285 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-access-checklist.md +261 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-transaction-checklist.md +390 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/domain-logic-checklist.md +295 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/form-plugin-checklist.md +508 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/infra-checklist.md +254 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ksql-checklist.md +305 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/lifecycle-checklist.md +298 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/operation-plugin-checklist.md +442 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/test-mock-checklist.md +120 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ui-performance-checklist.md +320 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +336 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +121 -0
- package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +295 -0
- package/vendor/kingdee-skills/ok-cosmic/README.md +460 -0
- package/vendor/kingdee-skills/ok-cosmic/SKILL.md +287 -0
- package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +17 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BatchImportPluginTemplate.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BillPlugInTemplate.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ConvertPlugInTemplate.java +255 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/FormPluginTemplate.java +597 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/IWorkflowPluginTemplate.java +91 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ListPluginTemplate.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpPluginTemplate.java +201 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpenApiControllerTemplate.java +103 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/PrintPluginTemplate.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportFormPluginTemplate.java +257 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportListDataPluginTemplate.java +70 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/StandardTreeListPluginTemplate.java +130 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TaskTemplate.java +80 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TreeListPluginTemplate.java +152 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/WriteBackPlugInTemplate.java +286 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/attachment/AttachmentUploadBindSample.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/BotpTracePushSample.java +168 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/SampleConvertPlugin.java +223 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/cache/SampleCacheUsage.java +218 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/concurrent/SampleThreadPoolBatch.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectCrudSample.java +205 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectOpsSample.java +100 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/BeforeOperationConfirmSample.java +217 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ConfirmDialogSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/EntryRowCalculateSample.java +116 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/F7FilterSample.java +134 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/GetAndSetValueSample.java +176 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/HyperlinkJumpSample.java +124 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/OpenBillModalSample.java +253 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ReturnParentDataSample.java +295 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/TreeControlSample.java +140 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ViewControlOpsSample.java +132 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPluginBasicSample.java +170 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPreOpenFilterSample.java +68 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/message/MessageNotifySample.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/SampleMQConsumer.java +198 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/sample_mq.xml +15 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OpAddValidatorsSample.java +137 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java +228 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/package-info.java +19 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BaseDataQuerySample.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BatchQuerySample.java +368 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/DataSetQueryStatSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportFormPlugin.java +179 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportListDataPlugin.java +616 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/snippets-guide.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/task/ScheduleTaskSample.java +160 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/workflow/SampleWorkflowPlugin.java +302 -0
- package/vendor/kingdee-skills/ok-cosmic/manifest.json +78 -0
- package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +903 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/attachment-api.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/botp-convert.md +98 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/dynamic-object.md +113 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/entity-metadata.md +123 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/event-lifecycle.md +184 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/flex-prop.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/form-utils.md +133 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/operate-chain.md +159 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/plugin-base.md +218 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/query-dataset.md +149 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/request-context.md +88 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/view-handler.md +157 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-bill.md +76 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-botp.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-form.md +165 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-import.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-list.md +227 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-openapi.md +112 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-operation.md +135 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-print.md +65 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-data.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-form.md +90 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-task.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-tree-list.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-workflow.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-writeback.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-algo.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-cache.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-model-svc.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-object.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-entity-model.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-exception.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-file.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-id.md +47 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-lock.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-log.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-network-control.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-orm-access.md +78 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-request-context.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-threadpool.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-tx.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-utils.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/requirements.txt +2 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +24 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +48 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/cheat-sheet.md +256 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +140 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +222 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +94 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/platform-baseline.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +109 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +204 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +910 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +359 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +181 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +389 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +856 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +262 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +293 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +2 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +393 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +176 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +375 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +434 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +36 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +186 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +40 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +142 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic-docs.db +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic.json +13 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +18 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +53 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
- package/vendor/kingdee-skills/ok-ksql/SKILL.md +81 -0
- package/vendor/kingdee-skills/ok-ksql/agents/openai.yaml +7 -0
- package/vendor/kingdee-skills/ok-ksql/manifest.json +14 -0
- package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +452 -0
- package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +363 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# Common Module 公共模块测试模式
|
|
2
|
+
|
|
3
|
+
## 适用范围
|
|
4
|
+
|
|
5
|
+
`<模块组>-common` 工程中的所有类,按类型分为三种测试模式:
|
|
6
|
+
- **POJO / DTO / Bean 类**:纯数据对象,getter/setter 测试
|
|
7
|
+
- **枚举类(Enum)**:含业务方法的枚举
|
|
8
|
+
- **工具类(Utils)**:含静态方法的工具类
|
|
9
|
+
|
|
10
|
+
## 测试文件位置
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
<模块组>-common/src/test/java/kd/<包路径>/common/{subpackage}/XxxTest.java
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
与被测类保持相同的包路径。
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## POJO / DTO / Bean 测试模式 {#POJO}
|
|
21
|
+
|
|
22
|
+
### 适用类型
|
|
23
|
+
|
|
24
|
+
纯数据对象类,只包含属性字段和 getter/setter 方法。
|
|
25
|
+
如:`InvokeResult`、`ExecuteTaskModel`、`PlanPushTransferInfo`、`DailyPlanBean` 等。
|
|
26
|
+
|
|
27
|
+
### 基类选择
|
|
28
|
+
|
|
29
|
+
| 场景 | 基类 |
|
|
30
|
+
|------|------|
|
|
31
|
+
| 纯 POJO(无框架依赖) | 无需基类,或继承 `AbstractJunitNoDependenciesResManagerTest` |
|
|
32
|
+
| 含 Builder 模式 | 同上 |
|
|
33
|
+
|
|
34
|
+
### 模板结构
|
|
35
|
+
|
|
36
|
+
```java
|
|
37
|
+
package kd.<包路径>.common.pojo;
|
|
38
|
+
|
|
39
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
40
|
+
import org.junit.Before;
|
|
41
|
+
import org.junit.Test;
|
|
42
|
+
|
|
43
|
+
import static org.junit.Assert.*;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* XxxModel 单元测试
|
|
47
|
+
* @author 作者
|
|
48
|
+
* @date YYYY/MM/DD
|
|
49
|
+
*/
|
|
50
|
+
public class XxxModelTest {
|
|
51
|
+
|
|
52
|
+
private XxxModel model;
|
|
53
|
+
|
|
54
|
+
@Before
|
|
55
|
+
public void setUp() {
|
|
56
|
+
model = new XxxModel();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@UnittestCaseInfo(
|
|
60
|
+
author = "<name> <<name>@kingdee.com>",
|
|
61
|
+
title = "Test get set fieldName",
|
|
62
|
+
targetClass = "kd.<包路径>.common.pojo.XxxModel",
|
|
63
|
+
targetMethod = "getsetfieldname",
|
|
64
|
+
lastUpdateTime = "yyyy-MM-dd HH:mm:ss",
|
|
65
|
+
lastUpdateAuthor = "<name> <<name>@kingdee.com>",
|
|
66
|
+
methodSignature = "public String getFieldName() / public void setFieldName(String value)",
|
|
67
|
+
testPoints = {"Functionality"},
|
|
68
|
+
description = "Test get set fieldName"
|
|
69
|
+
)
|
|
70
|
+
@Test
|
|
71
|
+
public void testGetSetFieldName() {
|
|
72
|
+
// step 设置属性
|
|
73
|
+
String value = "testValue";
|
|
74
|
+
model.setFieldName(value);
|
|
75
|
+
|
|
76
|
+
// assert 验证 getter 返回值
|
|
77
|
+
assertEquals(value, model.getFieldName());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Test
|
|
81
|
+
public void testSuccessFactory() {
|
|
82
|
+
// step 测试静态工厂方法
|
|
83
|
+
XxxModel result = XxxModel.success("data");
|
|
84
|
+
|
|
85
|
+
// assert 验证工厂方法结果
|
|
86
|
+
assertTrue(result.isSuccess());
|
|
87
|
+
assertEquals("data", result.getData());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Test
|
|
91
|
+
public void testToString() {
|
|
92
|
+
// step 设置属性
|
|
93
|
+
model.setFieldName("test");
|
|
94
|
+
|
|
95
|
+
// assert 验证 toString
|
|
96
|
+
String str = model.toString();
|
|
97
|
+
assertTrue(str.contains("fieldName=test"));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### POJO 测试要点
|
|
103
|
+
|
|
104
|
+
1. **不需要任何 Mock** — 纯 Java 对象,直接 new 和调用
|
|
105
|
+
2. **每个 getter/setter 一个测试方法**
|
|
106
|
+
3. **静态工厂方法**(如 `success()`/`failure()`)单独测试
|
|
107
|
+
4. **Builder 模式**需测试链式调用和 `build()` 结果
|
|
108
|
+
5. **toString()** 验证包含关键属性
|
|
109
|
+
|
|
110
|
+
### Builder 模式测试示例
|
|
111
|
+
|
|
112
|
+
```java
|
|
113
|
+
@Test
|
|
114
|
+
public void testBuilder() {
|
|
115
|
+
XxxModel model = new XxxModel.Builder()
|
|
116
|
+
.setField1("value1")
|
|
117
|
+
.setField2(100L)
|
|
118
|
+
.build();
|
|
119
|
+
|
|
120
|
+
assertEquals("value1", model.getField1());
|
|
121
|
+
assertEquals(Long.valueOf(100L), model.getField2());
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 枚举类测试模式 {#Enum}
|
|
128
|
+
|
|
129
|
+
### 适用类型
|
|
130
|
+
|
|
131
|
+
含业务方法的枚举类(不是纯值枚举),如 `PushOperationCodeEnum`、`ExecuteTaskStatusEnum` 等。
|
|
132
|
+
纯值枚举(只有常量值没有方法)一般不需要写测试。
|
|
133
|
+
|
|
134
|
+
### 基类选择
|
|
135
|
+
|
|
136
|
+
继承 `AbstractJunitNoDependenciesTest`(不需要 ResManager)
|
|
137
|
+
|
|
138
|
+
### 模板结构
|
|
139
|
+
|
|
140
|
+
```java
|
|
141
|
+
package kd.<包路径>.common.enums;
|
|
142
|
+
|
|
143
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
144
|
+
import kd.bos.unittest.AbstractJunitNoDependenciesTest;
|
|
145
|
+
import org.junit.Test;
|
|
146
|
+
|
|
147
|
+
public class XxxEnumTest extends AbstractJunitNoDependenciesTest {
|
|
148
|
+
|
|
149
|
+
@UnittestCaseInfo(
|
|
150
|
+
author = "<name> <<name>@kingdee.com>",
|
|
151
|
+
title = "Test getByCode with valid code",
|
|
152
|
+
targetClass = "kd.<包路径>.common.enums.XxxEnum",
|
|
153
|
+
targetMethod = "getbycode",
|
|
154
|
+
lastUpdateTime = "yyyy-MM-dd HH:mm:ss",
|
|
155
|
+
lastUpdateAuthor = "<name> <<name>@kingdee.com>",
|
|
156
|
+
methodSignature = "public static XxxEnum getByCode(String code)",
|
|
157
|
+
testPoints = {"Functionality"},
|
|
158
|
+
description = "Test getByCode with valid code"
|
|
159
|
+
)
|
|
160
|
+
@Test
|
|
161
|
+
public void testGetByCode_ValidCode() {
|
|
162
|
+
// step 测试有效的枚举 code
|
|
163
|
+
XxxEnum result = XxxEnum.getByCode("A");
|
|
164
|
+
|
|
165
|
+
// assert
|
|
166
|
+
assertEquals(XxxEnum.SOME_VALUE, result);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@Test
|
|
170
|
+
public void testGetByCode_InvalidCode() {
|
|
171
|
+
// step 测试无效的枚举 code
|
|
172
|
+
XxxEnum result = XxxEnum.getByCode("INVALID");
|
|
173
|
+
|
|
174
|
+
// assert 应返回 null
|
|
175
|
+
assertNull(result);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Test
|
|
179
|
+
public void testGetByCode_EmptyCode() {
|
|
180
|
+
// step 测试空字符串
|
|
181
|
+
String result = XxxEnum.matchMethod("");
|
|
182
|
+
|
|
183
|
+
// assert
|
|
184
|
+
assertEquals("", result);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 枚举测试要点
|
|
190
|
+
|
|
191
|
+
1. 测试**有效值**、**无效值**、**空值**三种场景
|
|
192
|
+
2. 测试枚举的 `getCode()` / `getName()` 等访问器
|
|
193
|
+
3. 测试枚举的匹配/转换方法(如 `matchPushTargetBill()`)
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 工具类测试模式 {#Utils}
|
|
198
|
+
|
|
199
|
+
### 适用类型
|
|
200
|
+
|
|
201
|
+
`<模块组>-common/src/main/java/kd/<包路径>/common/utils/` 下的工具类,
|
|
202
|
+
如 `BillPushUtil`、`FormPluginUtil`、`ApiInterfaceUtil`、`MetadataUtils` 等。
|
|
203
|
+
|
|
204
|
+
### 基类选择
|
|
205
|
+
|
|
206
|
+
| 场景 | 基类 |
|
|
207
|
+
|------|------|
|
|
208
|
+
| 依赖多个常见服务 | 继承 common 包的 `BaseTest`(已封装 10 个常用 Mock) |
|
|
209
|
+
| 依赖少量特定服务 | 继承 `AbstractJunitNoDependenciesResManagerTest`,自行管理 Mock |
|
|
210
|
+
|
|
211
|
+
### common 包 BaseTest 预置的 Mock
|
|
212
|
+
|
|
213
|
+
common 包的 `BaseTest`(`kd.<包路径>.common.BaseTest`,实际路径需在 `<模块组>-common/src/test/java/` 下查找)预置了:
|
|
214
|
+
- OrgUnitServiceHelper
|
|
215
|
+
- BillTypeParamHelper
|
|
216
|
+
- ResManager(thenAnswer 返回第一个参数)
|
|
217
|
+
- SystemParamServiceHelper
|
|
218
|
+
- QueryServiceHelper
|
|
219
|
+
- BusinessDataServiceHelper
|
|
220
|
+
- OperationServiceHelper
|
|
221
|
+
- BaseDataServiceHelper
|
|
222
|
+
- SaveServiceHelper
|
|
223
|
+
- **EntityMetadataCache**(比 business 工程多了这个)
|
|
224
|
+
|
|
225
|
+
### 模板结构
|
|
226
|
+
|
|
227
|
+
```java
|
|
228
|
+
package kd.<包路径>.common.utils;
|
|
229
|
+
|
|
230
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
231
|
+
import kd.bos.unittest.mock.DynamicObjectMocker;
|
|
232
|
+
import kd.<包路径>.common.BaseTest; // common 包自带的 BaseTest(实际包路径需查找)
|
|
233
|
+
import org.junit.Test;
|
|
234
|
+
import org.mockito.MockedStatic;
|
|
235
|
+
|
|
236
|
+
import static org.mockito.ArgumentMatchers.*;
|
|
237
|
+
import static org.mockito.Mockito.*;
|
|
238
|
+
|
|
239
|
+
public class XxxUtilTest extends BaseTest {
|
|
240
|
+
|
|
241
|
+
// 如需额外 Mock(BaseTest 未覆盖的),在此声明
|
|
242
|
+
// MockedStatic<SpecialHelper> specialHelper;
|
|
243
|
+
|
|
244
|
+
@UnittestCaseInfo(
|
|
245
|
+
author = "<name> <<name>@kingdee.com>",
|
|
246
|
+
title = "Test method with valid input",
|
|
247
|
+
targetClass = "kd.<包路径>.common.utils.XxxUtil",
|
|
248
|
+
targetMethod = "methodname",
|
|
249
|
+
lastUpdateTime = "yyyy-MM-dd HH:mm:ss",
|
|
250
|
+
lastUpdateAuthor = "<name> <<name>@kingdee.com>",
|
|
251
|
+
methodSignature = "public static ReturnType methodName(params)",
|
|
252
|
+
testPoints = {"Functionality"},
|
|
253
|
+
description = "Test method with valid input"
|
|
254
|
+
)
|
|
255
|
+
@Test
|
|
256
|
+
public void testMethod_ValidInput() {
|
|
257
|
+
//step 配置 Mock 返回值(直接使用 BaseTest 的成员变量)
|
|
258
|
+
queryServiceHelper.when(() -> QueryServiceHelper.query(anyString(), anyString(), any()))
|
|
259
|
+
.thenReturn(new DynamicObjectMocker().add("id", 1L).getCollection());
|
|
260
|
+
|
|
261
|
+
//step 执行被测方法
|
|
262
|
+
Object result = XxxUtil.targetMethod(param);
|
|
263
|
+
|
|
264
|
+
//assert 断言结果
|
|
265
|
+
assertNotNull(result);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
@Test
|
|
269
|
+
public void testMethod_EmptyInput() {
|
|
270
|
+
//step 测试空输入
|
|
271
|
+
Object result = XxxUtil.targetMethod(null);
|
|
272
|
+
|
|
273
|
+
//assert
|
|
274
|
+
assertNull(result);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### 工具类特殊技巧
|
|
280
|
+
|
|
281
|
+
#### 1. MockedConstruction(Mock 构造函数)
|
|
282
|
+
|
|
283
|
+
> 此为通用技巧,详见 SKILL.md 2.8 节。此处展示 common 工程的典型用法。
|
|
284
|
+
|
|
285
|
+
当工具类内部 new 了某个对象时,使用 `Mockito.mockConstruction`:
|
|
286
|
+
|
|
287
|
+
```java
|
|
288
|
+
@Test
|
|
289
|
+
public void testDoPush() {
|
|
290
|
+
try (MockedStatic<ConvertServiceHelper> convertServiceHelper = mockStatic(ConvertServiceHelper.class);
|
|
291
|
+
MockedConstruction<PushArgs> pushArgsMock = Mockito.mockConstruction(PushArgs.class)) {
|
|
292
|
+
|
|
293
|
+
//step 执行
|
|
294
|
+
BillPushUtil.doPush("src", "target", "ruleId", params, rows);
|
|
295
|
+
|
|
296
|
+
//assert
|
|
297
|
+
convertServiceHelper.verify(() -> ConvertServiceHelper.push(any()));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### 2. Mock 表单控件
|
|
303
|
+
|
|
304
|
+
测试 FormPluginUtil 等涉及 UI 控件的方法:
|
|
305
|
+
|
|
306
|
+
```java
|
|
307
|
+
@Test
|
|
308
|
+
public void testGetSelectedRowData() {
|
|
309
|
+
// step Mock 表单控件
|
|
310
|
+
IFormView view = mock(IFormView.class);
|
|
311
|
+
EntryGrid entryGrid = mock(EntryGrid.class);
|
|
312
|
+
IDataModel model = mock(IDataModel.class);
|
|
313
|
+
|
|
314
|
+
when(view.getControl("entryKey")).thenReturn(entryGrid);
|
|
315
|
+
when(entryGrid.getSelectRows()).thenReturn(new int[]{0, 1});
|
|
316
|
+
|
|
317
|
+
DynamicObjectCollection entries = new DynamicObjectCollection();
|
|
318
|
+
entries.add(new DynamicObjectMocker().add("id", 1).getObject());
|
|
319
|
+
entries.add(new DynamicObjectMocker().add("id", 2).getObject());
|
|
320
|
+
when(model.getEntryCurrentRowIndex("entryKey")).thenReturn(0);
|
|
321
|
+
|
|
322
|
+
// step 执行
|
|
323
|
+
List<DynamicObject> result = FormPluginUtil.getSelectedRowData(model, view, "entryKey");
|
|
324
|
+
|
|
325
|
+
// assert
|
|
326
|
+
assertEquals(2, result.size());
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### 3. try-with-resources 管理方法级 Mock
|
|
331
|
+
|
|
332
|
+
当某些 MockedStatic 只在单个测试方法中使用时:
|
|
333
|
+
|
|
334
|
+
```java
|
|
335
|
+
@Test
|
|
336
|
+
public void testMethod() {
|
|
337
|
+
try (MockedStatic<SpecialHelper> specialHelper = mockStatic(SpecialHelper.class)) {
|
|
338
|
+
specialHelper.when(() -> SpecialHelper.doSomething(any())).thenReturn(result);
|
|
339
|
+
// ... 测试逻辑
|
|
340
|
+
}
|
|
341
|
+
// 自动关闭,无需 @After
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## common 工程类型分布参考
|
|
348
|
+
|
|
349
|
+
| 类型 | 数量 | 是否需要测试 | 测试模式 |
|
|
350
|
+
|------|------|------------|---------|
|
|
351
|
+
| 常量类(Const) | ~21 | 通常不需要 | — |
|
|
352
|
+
| 枚举类(Enum) | ~24 | 含业务方法时需要 | Enum 模式 |
|
|
353
|
+
| POJO/DTO/Bean | ~25 | 需要 | POJO 模式 |
|
|
354
|
+
| 工具类(Utils) | ~19 | 需要 | Utils 模式 |
|
|
355
|
+
| 业务模块类 | ~12 | 需要 | Utils 模式 |
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# ConvertPlugin 转换插件测试模式
|
|
2
|
+
|
|
3
|
+
## 适用范围
|
|
4
|
+
|
|
5
|
+
`<模块组>-opplugin` 工程中的 BOTP 转换插件(下推/反写插件),如:
|
|
6
|
+
- 继承 `AbstractConvertPlugIn` 的类
|
|
7
|
+
- 实现 `afterConvert`、`beforeBuildRowCondition`、`afterBuildDrawFilter` 等方法的类
|
|
8
|
+
|
|
9
|
+
## 测试文件位置
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
<模块组>-opplugin/src/test/java/kd/<包路径>/opplugin/convertplugin/XxxConvertPluginTest.java
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
或
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
<模块组>-opplugin/src/test/java/kd/<包路径>/opplugin/common/botp/XxxBotpConvertPluginTest.java
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 模板结构
|
|
22
|
+
|
|
23
|
+
```java
|
|
24
|
+
package kd.<包路径>.opplugin.convertplugin;
|
|
25
|
+
|
|
26
|
+
import kd.bos.dataentity.entity.DynamicObject;
|
|
27
|
+
import kd.bos.entity.BillEntityType;
|
|
28
|
+
import kd.bos.entity.ExtendedDataEntity;
|
|
29
|
+
import kd.bos.entity.botp.runtime.ConvertOperationResult;
|
|
30
|
+
import kd.bos.form.unittest.DisplayName;
|
|
31
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
32
|
+
import kd.bos.unittest.AbstractJunitNoDependenciesResManagerTest;
|
|
33
|
+
import kd.bos.unittest.mock.DynamicObjectMocker;
|
|
34
|
+
import org.junit.After;
|
|
35
|
+
import org.junit.Before;
|
|
36
|
+
import org.junit.Test;
|
|
37
|
+
import org.mockito.MockedStatic;
|
|
38
|
+
|
|
39
|
+
import static org.mockito.ArgumentMatchers.*;
|
|
40
|
+
import static org.mockito.Mockito.*;
|
|
41
|
+
|
|
42
|
+
public class XxxConvertPluginTest extends AbstractJunitNoDependenciesResManagerTest {
|
|
43
|
+
|
|
44
|
+
MockedStatic<SomeHelper> someHelper;
|
|
45
|
+
|
|
46
|
+
@Before
|
|
47
|
+
public void before() {
|
|
48
|
+
someHelper = mockStatic(SomeHelper.class);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@After
|
|
52
|
+
public void after() {
|
|
53
|
+
someHelper.close();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 构建源单和目标单数据
|
|
57
|
+
private ExtendedDataEntity[] buildSrcData() {
|
|
58
|
+
DynamicObject srcBill = new DynamicObjectMocker()
|
|
59
|
+
.add("id", 1L)
|
|
60
|
+
.add("billno", "SRC-001")
|
|
61
|
+
.add("entryentity", new DynamicObjectMocker()
|
|
62
|
+
.add("id", 10L)
|
|
63
|
+
.add("qty", BigDecimal.TEN)
|
|
64
|
+
.getCollection())
|
|
65
|
+
.getObject();
|
|
66
|
+
return new ExtendedDataEntity[]{new ExtendedDataEntity(srcBill, 0, 0)};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private ExtendedDataEntity[] buildDestData() {
|
|
70
|
+
DynamicObject destBill = new DynamicObjectMocker()
|
|
71
|
+
.add("id", 2L)
|
|
72
|
+
.add("entryentity", new DynamicObjectMocker()
|
|
73
|
+
.add("id", 20L)
|
|
74
|
+
.add("srcqty", BigDecimal.TEN)
|
|
75
|
+
.getCollection())
|
|
76
|
+
.getObject();
|
|
77
|
+
return new ExtendedDataEntity[]{new ExtendedDataEntity(destBill, 0, 0)};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@UnittestCaseInfo(
|
|
81
|
+
author = "<name> <<name>@kingdee.com>",
|
|
82
|
+
title = "Test after convert normal",
|
|
83
|
+
targetClass = "kd.<包路径>.opplugin.convertplugin.XxxConvertPlugin",
|
|
84
|
+
targetMethod = "afterconvert",
|
|
85
|
+
lastUpdateTime = "yyyy-MM-dd HH:mm:ss",
|
|
86
|
+
lastUpdateAuthor = "<name> <<name>@kingdee.com>",
|
|
87
|
+
methodSignature = "public void afterConvert(AfterConvertEventArgs e)",
|
|
88
|
+
testPoints = {"Functionality"},
|
|
89
|
+
description = "Test after convert normal"
|
|
90
|
+
)
|
|
91
|
+
@Test
|
|
92
|
+
@DisplayName("转换后处理:正常场景")
|
|
93
|
+
public void testAfterConvert_Normal() {
|
|
94
|
+
//step 构建插件实例
|
|
95
|
+
XxxConvertPlugin plugin = new XxxConvertPlugin();
|
|
96
|
+
|
|
97
|
+
//step 构建转换结果
|
|
98
|
+
ConvertOperationResult convertResult = mock(ConvertOperationResult.class);
|
|
99
|
+
// 配置源单和目标单数据...
|
|
100
|
+
|
|
101
|
+
//step 执行转换后方法
|
|
102
|
+
plugin.afterConvert(afterConvertEventArgs);
|
|
103
|
+
|
|
104
|
+
//assert 验证目标单字段是否被正确赋值
|
|
105
|
+
assertEquals(expectedValue, destBill.get("fieldKey"));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 关键要点
|
|
111
|
+
|
|
112
|
+
1. **转换插件测试重点**是验证源单字段到目标单字段的映射逻辑
|
|
113
|
+
2. 通常需要 Mock `BillEntityType`、`ExtendedDataEntitySet` 等转换框架对象
|
|
114
|
+
3. 源单和目标单都用 DynamicObjectMocker 构造
|
|
115
|
+
4. 断言重点:目标单的字段值是否被正确设置
|
|
116
|
+
|
|
117
|
+
## Mock 转换框架对象示例
|
|
118
|
+
|
|
119
|
+
```java
|
|
120
|
+
// Mock BillEntityType
|
|
121
|
+
BillEntityType srcEntityType = mock(BillEntityType.class);
|
|
122
|
+
when(srcEntityType.getName()).thenReturn("mmc_outsourcesend");
|
|
123
|
+
|
|
124
|
+
BillEntityType destEntityType = mock(BillEntityType.class);
|
|
125
|
+
when(destEntityType.getName()).thenReturn("mmc_processsettle");
|
|
126
|
+
|
|
127
|
+
// Mock ExtendedDataEntitySet
|
|
128
|
+
ExtendedDataEntitySet srcDataEntitySet = mock(ExtendedDataEntitySet.class);
|
|
129
|
+
when(srcDataEntitySet.FindByPK(anyLong())).thenReturn(srcExtendedDataEntity);
|
|
130
|
+
```
|