$npx -y skills add echoVic/boss-skill --skill test-execution测试执行方法,包含测试框架检测、测试运行、结果解析
| 1 | # 测试执行方法 |
| 2 | |
| 3 | ## 强制要求:真实执行测试 |
| 4 | |
| 5 | **你必须真正执行测试,禁止生成 Mock 数据!** |
| 6 | |
| 7 | ## 测试执行流程 |
| 8 | |
| 9 | 1. **检测项目类型和测试框架** |
| 10 | 2. **根据项目类型执行测试** |
| 11 | 3. **执行 E2E / 集成测试** |
| 12 | 4. **解析测试输出**(总数、通过数、失败数、覆盖率) |
| 13 | |
| 14 | ## 测试框架检测 |
| 15 | |
| 16 | ### JavaScript/TypeScript |
| 17 | - Jest: `jest.config.js`, `"jest"` in package.json |
| 18 | - Vitest: `vitest.config.js`, `"vitest"` in package.json |
| 19 | - Playwright: `playwright.config.js` |
| 20 | - Cypress: `cypress.json` |
| 21 | |
| 22 | ### Python |
| 23 | - pytest: `pytest.ini`, `"pytest"` in dependencies |
| 24 | - unittest: 内置 |
| 25 | |
| 26 | ### Go |
| 27 | - `*_test.go` 文件 |
| 28 | |
| 29 | ## 测试命令 |
| 30 | |
| 31 | | 语言 | 单元测试 | E2E测试 | |
| 32 | |------|----------|---------| |
| 33 | | Node.js | `npm test` | `npx playwright test` | |
| 34 | | Python | `pytest` | `pytest tests/e2e` | |
| 35 | | Go | `go test ./...` | - | |
| 36 | |
| 37 | ## Playwright E2E 执行细节 |
| 38 | |
| 39 | > **完整方法论**:详见 `Skill(skill: "qa/e2e-playwright")` |
| 40 | |
| 41 | ### 检测 Playwright 项目 |
| 42 | |
| 43 | 检查以下标志确认项目使用 Playwright: |
| 44 | - `playwright.config.ts` 或 `playwright.config.js` 存在 |
| 45 | - `package.json` 中包含 `@playwright/test` 依赖 |
| 46 | - `e2e/` 或 `tests/e2e/` 目录存在 |
| 47 | |
| 48 | ### 执行命令 |
| 49 | |
| 50 | ```bash |
| 51 | # 安装浏览器(首次或 CI 环境) |
| 52 | npx playwright install --with-deps |
| 53 | |
| 54 | # 运行全部 E2E 测试 |
| 55 | npx playwright test |
| 56 | |
| 57 | # 仅 critical 标签(门禁加速) |
| 58 | npx playwright test --grep @critical |
| 59 | |
| 60 | # 指定浏览器 |
| 61 | npx playwright test --project=chromium |
| 62 | |
| 63 | # JSON 报告(门禁解析用) |
| 64 | npx playwright test --reporter=json |
| 65 | ``` |
| 66 | |
| 67 | ### 结果解析 |
| 68 | |
| 69 | Playwright JSON 报告关键字段: |
| 70 | |
| 71 | | 字段 | 说明 | |
| 72 | |------|------| |
| 73 | | `stats.expected` | 通过的测试数 | |
| 74 | | `stats.unexpected` | 失败的测试数 | |
| 75 | | `stats.flaky` | 重试后通过的测试数 | |
| 76 | | `stats.skipped` | 跳过的测试数 | |
| 77 | |
| 78 | ### 失败排查 |
| 79 | |
| 80 | ```bash |
| 81 | # 查看 trace(失败时自动生成) |
| 82 | npx playwright show-trace <trace.zip路径> |
| 83 | |
| 84 | # 打开 HTML 报告 |
| 85 | npx playwright show-report |
| 86 | ``` |