appbuilder-testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApp Builder Testing
App Builder测试
Generate and run Jest tests for Adobe App Builder actions and React Spectrum UI components. Scaffolds unit tests, integration tests, component tests, and mock helpers for Adobe SDKs.
为Adobe App Builder动作和React Spectrum UI组件生成并运行Jest测试。搭建单元测试、集成测试、组件测试以及Adobe SDK的模拟助手。
Pattern Quick-Reference
模式快速参考
Pick the template or reference that matches the user's intent. Default to for generic test requests.
assets/unit-test-template.js| User wants | Reference | Template / Asset |
|---|---|---|
| Unit test for an existing action | references/testing-patterns.md | assets/unit-test-template.js |
| Integration test against deployed action | references/testing-patterns.md | assets/integration-test-template.js |
| Component test for React Spectrum UI | references/component-testing-patterns.md | assets/component-test-template.js |
| Mock ExC Shell context in tests | references/component-testing-patterns.md | assets/shell-mock-helper.js |
| Mock AEM extension context in tests | references/component-testing-patterns.md | assets/uix-guest-mock-helper.js |
| Mock State SDK in tests | references/mock-catalog.md | assets/mock-state-sdk.js |
| Mock Files SDK in tests | references/mock-catalog.md | assets/mock-files-sdk.js |
| Mock Events SDK in tests | references/mock-catalog.md | assets/mock-events-sdk.js |
| Mock Database SDK in tests | references/mock-catalog.md | assets/mock-database-sdk.js |
| Full mock catalog (all SDKs) | references/mock-catalog.md | — |
| Contract test for API interactions | references/testing-patterns.md | — |
| Pre-deployment verification | references/checklist.md | — |
| Debug test failures | references/debugging.md | — |
选择与用户意图匹配的模板或参考文档。对于通用测试请求,默认使用。
assets/unit-test-template.js| 用户需求 | 参考文档 | 模板/资源 |
|---|---|---|
| 为现有动作编写单元测试 | references/testing-patterns.md | assets/unit-test-template.js |
| 针对已部署动作的集成测试 | references/testing-patterns.md | assets/integration-test-template.js |
| React Spectrum UI组件测试 | references/component-testing-patterns.md | assets/component-test-template.js |
| 在测试中模拟ExC Shell上下文 | references/component-testing-patterns.md | assets/shell-mock-helper.js |
| 在测试中模拟AEM扩展上下文 | references/component-testing-patterns.md | assets/uix-guest-mock-helper.js |
| 在测试中模拟State SDK | references/mock-catalog.md | assets/mock-state-sdk.js |
| 在测试中模拟Files SDK | references/mock-catalog.md | assets/mock-files-sdk.js |
| 在测试中模拟Events SDK | references/mock-catalog.md | assets/mock-events-sdk.js |
| 在测试中模拟Database SDK | references/mock-catalog.md | assets/mock-database-sdk.js |
| 完整模拟目录(所有SDK) | references/mock-catalog.md | — |
| API交互的契约测试 | references/testing-patterns.md | — |
| 部署前验证 | references/checklist.md | — |
| 调试测试失败 | references/debugging.md | — |
Fast Path (for clear requests)
快速路径(适用于明确请求)
When the user's request maps unambiguously to a single pattern above — they name a specific test type, reference a template, or describe a use case that clearly matches one entry — skip straight to generation. Use the matched template and proceed directly.
Examples of fast-path triggers:
- "Write tests for my action" → Read the action source, use , generate immediately
assets/unit-test-template.js - "Help me mock State SDK" → Use , inject into test file
assets/mock-state-sdk.js - "Add integration tests" → Use , configure for deployed action
assets/integration-test-template.js - "Run tests with coverage" → Execute or
npx jest --coverageaio app test - "Test my component/page/form/table" → Read the component source, use , wrap in Provider
assets/component-test-template.js - "Mock shell context" → Use , inject into test file
assets/shell-mock-helper.js - "Test my AEM extension component" → Use +
assets/uix-guest-mock-helper.jsassets/component-test-template.js
If there is any ambiguity — multiple test types needed, project structure unclear, or the user hasn't specified enough — fall through to the full workflow below.
当用户的请求明确对应上述单一模式——他们指定了特定测试类型、参考模板,或描述的用例清晰匹配某一项时,直接跳转到生成步骤。使用匹配的模板并立即执行。
快速路径触发示例:
- "为我的动作编写测试" → 读取动作源代码,使用,立即生成
assets/unit-test-template.js - "帮我模拟State SDK" → 使用,注入测试文件
assets/mock-state-sdk.js - "添加集成测试" → 使用,为已部署动作配置
assets/integration-test-template.js - "运行带覆盖率的测试" → 执行或
npx jest --coverageaio app test - "测试我的组件/页面/表单/表格" → 读取组件源代码,使用,用Provider包裹
assets/component-test-template.js - "模拟shell上下文" → 使用,注入测试文件
assets/shell-mock-helper.js - "测试我的AEM扩展组件" → 使用+
assets/uix-guest-mock-helper.jsassets/component-test-template.js
如果存在任何歧义——需要多种测试类型、项目结构不明确,或用户未提供足够信息——则使用下方的完整工作流。
Quick Reference
快速参考
- Test directory: Place test files in mirroring the action path, e.g.,
test/.test/actions/<action-name>/index.test.js - Jest configuration: App Builder projects use Jest by default. Config lives in or
package.json.jest.config.js - Test command: (wrapper) or
aio app test(direct).npx jest --coverage - Mock pattern: Use at the top of test files to mock Adobe SDK dependencies before importing the action.
jest.mock() - Response shape: All actions return — assert both in every test.
{ statusCode, body } - Error paths: Always test 200 (success), 400 (bad input), and 500 (SDK failure) scenarios.
- CommonJS: Action test files use and
require()(not ES imports).module.exports - Component test directory: (or
test/web-src/components/<ComponentName>.test.js).test/components/ - Provider wrapper: Always wrap in — Spectrum renders nothing without it.
<Provider theme={defaultTheme}> - ARIA selectors: Use , not CSS classes — see
getByRole()selector table.references/component-testing-patterns.md - Async testing: Use for data that appears async,
findBy*for absence,queryBy*for state changes.waitFor
- 测试目录: 将测试文件放在目录中,与动作路径镜像对应,例如
test/。test/actions/<action-name>/index.test.js - Jest配置: App Builder项目默认使用Jest。配置文件位于或
package.json中。jest.config.js - 测试命令: (包装器)或
aio app test(直接命令)。npx jest --coverage - 模拟模式: 在测试文件顶部使用,在导入动作之前模拟Adobe SDK依赖。
jest.mock() - 响应格式: 所有动作返回——在每个测试中都要断言这两个字段。
{ statusCode, body } - 错误路径: 始终测试200(成功)、400(输入错误)和500(SDK失败)场景。
- CommonJS: 动作测试文件使用和
require()(而非ES导入)。module.exports - 组件测试目录: (或
test/web-src/components/<ComponentName>.test.js)。test/components/ - Provider包装器: 始终用包裹——没有它,Spectrum无法渲染任何内容。
<Provider theme={defaultTheme}> - ARIA选择器: 使用,而非CSS类——详见
getByRole()中的选择器表格。references/component-testing-patterns.md - 异步测试: 对异步加载的数据使用,检查元素不存在使用
findBy*,状态变化使用queryBy*。waitFor
Full Workflow (for ambiguous or complex requests)
完整工作流(适用于模糊或复杂请求)
- Scan project structure — Check for existing directory,
test/, and test scripts injest.config.js. Scan bothpackage.jsonfor actions ANDsrc/for UI components.web-src/ - Identify targets to test — Parse (or
ext.config.yaml) for declared actions and their source paths. Checkapp.config.yamlfor React components.web-src/src/components/ - Determine test types needed — Unit tests for logic, integration tests for deployed actions, contract tests for API interactions.
- **For each action:**a. Read the action source to identify SDK dependencies (State, Files, Events, Logger, etc.).b. Generate unit test using as the base.c. Inject appropriate mocks from
assets/unit-test-template.jsbased on detected dependencies.d. Add error scenario tests (missing params, auth failures, SDK errors).references/mock-catalog.md - **For each UI component:**a. Read the component source to identify dependencies (shell context, UIX guest, action calls).b. Generate component test using as the base.c. Wrap all renders in
assets/component-test-template.js— Spectrum renders nothing without it.d. Inject shell mock (<Provider theme={defaultTheme}>) or UIX guest mock (assets/shell-mock-helper.js) as needed.e. Add loading, success, and error state tests for async data usingassets/uix-guest-mock-helper.jsandfindBy*.waitFor - Run tests — Execute or
aio app testand report results.npx jest --coverage - Validate — Check against before marking done.
references/checklist.md
- 扫描项目结构 —— 检查是否存在现有目录、
test/以及jest.config.js中的测试脚本。同时扫描package.json中的动作和src/中的UI组件。web-src/ - 确定测试目标 —— 解析(或
ext.config.yaml)中声明的动作及其源路径。检查app.config.yaml中的React组件。web-src/src/components/ - 确定所需测试类型 —— 针对逻辑的单元测试、针对已部署动作的集成测试、针对API交互的契约测试。
- **针对每个动作:**a. 读取动作源代码,识别SDK依赖(State、Files、Events、Logger等)。b. 以为基础生成单元测试。c. 根据检测到的依赖,从
assets/unit-test-template.js中注入相应的模拟。d. 添加错误场景测试(缺少参数、认证失败、SDK错误)。references/mock-catalog.md - **针对每个UI组件:**a. 读取组件源代码,识别依赖(shell上下文、UIX guest、动作调用)。b. 以为基础生成组件测试。c. 所有渲染都用
assets/component-test-template.js包裹——没有它,Spectrum无法渲染任何内容。d. 根据需要注入shell模拟(<Provider theme={defaultTheme}>)或UIX guest模拟(assets/shell-mock-helper.js)。e. 使用assets/uix-guest-mock-helper.js和findBy*为异步数据添加加载、成功和错误状态测试。waitFor - 运行测试 —— 执行或
aio app test并报告结果。npx jest --coverage - 验证 —— 在标记完成前对照检查。
references/checklist.md
Example User Prompts
用户示例提示
- "Write unit tests for my generic action"
- "Add integration tests for my deployed action"
- "My action uses State SDK — help me mock it in tests"
- "Run tests and show me coverage"
- "Set up Jest for my App Builder project"
- "Test my action handles errors properly"
- "Write component tests for my data table page"
- "Test my AEM extension panel component"
- "Help me mock shell context in my tests"
- "Add tests for my React Spectrum form"
- "为我的通用动作编写单元测试"
- "为我的已部署动作添加集成测试"
- "我的动作使用State SDK——帮我在测试中模拟它"
- "运行测试并显示覆盖率"
- "为我的App Builder项目设置Jest"
- "测试我的动作是否能正确处理错误"
- "为我的数据表页面编写组件测试"
- "测试我的AEM扩展面板组件"
- "帮我在测试中模拟shell上下文"
- "为我的React Spectrum表单添加测试"
Inputs To Request
需要请求的输入信息
- Current repository path and action file locations
- Which actions need tests (or test all declared actions)
- Target test types: unit, integration, contract, or all
- Whether action is deployed (needed for integration tests)
- 当前仓库路径和动作文件位置
- 需要测试哪些动作(或测试所有已声明的动作)
- 目标测试类型:单元、集成、契约,或全部
- 动作是否已部署(集成测试需要此信息)
Deliverables
交付物
- Test files in matching the action directory structure
test/ - Component test files in for UI components
test/web-src/components/ - Mock helpers for detected Adobe SDK dependencies
- Shell or UIX Guest mock helpers when components depend on context SDKs
- Jest configuration if not already present (including jsdom environment for component tests)
- Coverage report from test execution
- 位于目录中的测试文件,与动作目录结构匹配
test/ - 针对UI组件的测试文件,位于
test/web-src/components/ - 针对检测到的Adobe SDK依赖的模拟助手
- 当组件依赖上下文SDK时,提供Shell或UIX Guest模拟助手
- 如果尚未存在,提供Jest配置(包括组件测试所需的jsdom环境)
- 测试执行的覆盖率报告
Quality Bar
质量标准
- Every action test covers at minimum: success (200), bad input (400), and SDK failure (500) paths
- Mocks are isolated per test via
beforeEach(() => jest.clearAllMocks()) - No real SDK calls in unit tests — all external dependencies are mocked
- Tests are deterministic and can run offline (no network dependencies in unit tests)
- Coverage reporting is enabled (flag)
--coverage - All component tests wrap in — Spectrum renders nothing without it
<Provider theme={defaultTheme}>
- 每个动作测试至少覆盖:成功(200)、输入错误(400)和SDK失败(500)路径
- 通过确保每个测试的模拟是隔离的
beforeEach(() => jest.clearAllMocks()) - 单元测试中没有真实的SDK调用——所有外部依赖都已模拟
- 测试具有确定性,可离线运行(单元测试中无网络依赖)
- 已启用覆盖率报告(标志)
--coverage - 所有组件测试都用包裹——没有它,Spectrum无法渲染任何内容
<Provider theme={defaultTheme}>
References
参考文档
- Use for unit, integration, and contract test patterns with annotated examples.
references/testing-patterns.md - Use for React Spectrum component testing with Provider wrapping, ARIA selectors, and async patterns.
references/component-testing-patterns.md - Use for mock helpers covering all Adobe SDKs (State, Files, Events, Logger, Database, Shell, UIX Guest).
references/mock-catalog.md - Use for pre-deployment test verification.
references/checklist.md - Use for Jest unit test boilerplate (CommonJS).
assets/unit-test-template.js - Use for integration test against deployed actions.
assets/integration-test-template.js - Use for React Spectrum component test boilerplate with
assets/component-test-template.jshelper.renderWithSpectrum() - Use for ExC Shell context mock (
assets/shell-mock-helper.js).@adobe/exc-app - Use for AEM UIX Guest mock (
assets/uix-guest-mock-helper.js).@adobe/uix-guest - Use ,
assets/mock-state-sdk.js,assets/mock-files-sdk.js, andassets/mock-events-sdk.jsfor ready-to-use SDK mock setups.assets/mock-database-sdk.js
- 使用获取带有注释示例的单元、集成和契约测试模式。
references/testing-patterns.md - 使用获取React Spectrum组件测试的相关内容,包括Provider包裹、ARIA选择器和异步模式。
references/component-testing-patterns.md - 使用获取覆盖所有Adobe SDK(State、Files、Events、Logger、Database、Shell、UIX Guest)的模拟助手。
references/mock-catalog.md - 使用进行部署前测试验证。
references/checklist.md - 使用获取Jest单元测试模板(CommonJS)。
assets/unit-test-template.js - 使用获取针对已部署动作的集成测试模板。
assets/integration-test-template.js - 使用获取带有
assets/component-test-template.js助手的React Spectrum组件测试模板。renderWithSpectrum() - 使用获取ExC Shell上下文模拟(
assets/shell-mock-helper.js)。@adobe/exc-app - 使用获取AEM UIX Guest模拟(
assets/uix-guest-mock-helper.js)。@adobe/uix-guest - 使用、
assets/mock-state-sdk.js、assets/mock-files-sdk.js和assets/mock-events-sdk.js获取现成可用的SDK模拟设置。assets/mock-database-sdk.js
Common Issues
常见问题
- Tests fail with "Cannot find module": Ensure the action path in matches the actual file location. App Builder actions are typically at
require().src/dx-excshell-1/actions/<name>/index.js - Mocks not working: calls must appear before
jest.mock()of the module under test. Jest hoists mock declarations but order still matters for manual mocks.require() - State/Files SDK tests fail: These SDKs require Runtime environment for real calls. Always mock them in unit tests. Use (not
aio app run) for integration tests that need real SDK access.aio app dev - Coverage too low: Add tests for error branches — missing params, invalid auth headers, SDK failures, and timeout scenarios.
init() - ** vs
aio app test:**npx jestis a thin wrapper around Jest. Useaio app testdirectly for more control over flags and reporters.npx jest --coverage - Spectrum components render blank in tests: Missing wrapper. Use
<Provider theme={defaultTheme}>helper fromrenderWithSpectrum().assets/component-test-template.js - ARIA role queries return null: Spectrum components use ARIA roles, not CSS classes. See section g for the role reference table.
references/component-testing-patterns.md
- 测试失败,提示"Cannot find module": 确保中的动作路径与实际文件位置匹配。App Builder动作通常位于
require()。src/dx-excshell-1/actions/<name>/index.js - 模拟不生效: 调用必须出现在导入被测模块的
jest.mock()之前。Jest会提升模拟声明,但手动模拟的顺序仍然重要。require() - State/Files SDK测试失败: 这些SDK需要Runtime环境才能进行真实调用。在单元测试中始终模拟它们。对于需要真实SDK访问的集成测试,使用(而非
aio app run)。aio app dev - 覆盖率过低: 添加错误分支的测试——缺少参数、无效认证头、SDK失败和超时场景。
init() - vs
aio app test:npx jest是Jest的轻量包装器。直接使用aio app test可获得更多标志和报告器的控制权。npx jest --coverage - 测试中Spectrum组件渲染空白: 缺少包装器。使用
<Provider theme={defaultTheme}>中的assets/component-test-template.js助手。renderWithSpectrum() - ARIA角色查询返回null: Spectrum组件使用ARIA角色,而非CSS类。详见第g节的角色参考表格。
references/component-testing-patterns.md
Chaining
链式关联
- Chains FROM (test actions after implementation)
appbuilder-action-scaffolder - Chains FROM (test UI components after scaffolding)
appbuilder-ui-scaffolder - Chains TO (automated test execution in CI)
appbuilder-cicd-pipeline
- 从关联而来(实现动作后进行测试)
appbuilder-action-scaffolder - 从关联而来(搭建UI组件后进行测试)
appbuilder-ui-scaffolder - 关联到(在CI中自动执行测试)
appbuilder-cicd-pipeline