Bläddra i källkod

Organize test deliverables by coursework units

gangvy 3 månader sedan
förälder
incheckning
8001621972
32 ändrade filer med 434 tillägg och 23 borttagningar
  1. 40 4
      tests/README.md
  2. 17 0
      tests/api_tests/README.md
  3. 6 0
      tests/api_tests/reports/README.md
  4. 15 0
      tests/api_tests/reports/api_test_log.txt
  5. 7 0
      tests/api_tests/reports/api_test_summary.txt
  6. 44 3
      tests/api_tests/run_api_tests.ps1
  7. 13 1
      tests/auto_tests/README.md
  8. BIN
      tests/auto_tests/artifacts/AUTO-001-dashboard.png
  9. BIN
      tests/auto_tests/artifacts/AUTO-002-tickets.png
  10. BIN
      tests/auto_tests/artifacts/AUTO-003-sla.png
  11. BIN
      tests/auto_tests/artifacts/AUTO-004-knowledge.png
  12. BIN
      tests/auto_tests/artifacts/AUTO-005-files.png
  13. BIN
      tests/auto_tests/artifacts/AUTO-006-reviews.png
  14. BIN
      tests/auto_tests/artifacts/AUTO-007-test-plan.png
  15. 8 0
      tests/auto_tests/reports/README.md
  16. 21 0
      tests/auto_tests/reports/auto_test_log.txt
  17. 8 0
      tests/auto_tests/reports/auto_test_summary.txt
  18. 40 2
      tests/auto_tests/run_auto_tests.ps1
  19. 17 0
      tests/performance_tests/README.md
  20. 10 0
      tests/performance_tests/reports/README.md
  21. 5 0
      tests/performance_tests/reports/backend_performance_pending.txt
  22. 5 0
      tests/performance_tests/reports/frontend_performance_pending.txt
  23. 1 0
      tests/performance_tests/requirements.txt
  24. 24 4
      tests/performance_tests/run_backend_performance.ps1
  25. 24 4
      tests/performance_tests/run_frontend_performance.ps1
  26. 16 0
      tests/unit_tests/README.md
  27. 6 0
      tests/unit_tests/reports/README.md
  28. 9 0
      tests/unit_tests/reports/unit_test_log.txt
  29. 7 0
      tests/unit_tests/reports/unit_test_summary.txt
  30. 44 3
      tests/unit_tests/run_unit_tests.ps1
  31. 17 0
      tests/提交结构说明.md
  32. 30 2
      tests/测试结果汇总.md

+ 40 - 4
tests/README.md

@@ -1,15 +1,17 @@
-# ServicePilot 测试脚本目录说明
+# ServicePilot 综合测试脚本目录说明
 
-本目录按课程作业要求拆分为四类测试脚本:
+本目录按课程作业和历史实训提交方式拆分为四类测试单元。每个测试单元均包含测试说明、脚本入口和结果证据,便于分别提交、分别说明测试结果。
 
 ```text
 tests/
 ├─ unit_tests/          # 单元测试脚本
 ├─ api_tests/           # 接口测试脚本
-├─ auto_tests/          # 自动化测试脚本
+├─ auto_tests/          # 自动化测试脚本与页面截图
 └─ performance_tests/   # Locust 性能测试脚本
 ```
 
+提交结构说明见:`tests/提交结构说明.md`
+
 ## 1. 单元测试
 
 位置:`tests/unit_tests`
@@ -28,6 +30,13 @@ cd E:\软测\ServicePilot\tests\unit_tests
 powershell -ExecutionPolicy Bypass -File .\run_unit_tests.ps1
 ```
 
+结果输出:
+
+```text
+tests/unit_tests/reports/unit_test_log.txt
+tests/unit_tests/reports/unit_test_summary.txt
+```
+
 ## 2. 接口测试
 
 位置:`tests/api_tests`
@@ -46,6 +55,13 @@ cd E:\软测\ServicePilot\tests\api_tests
 powershell -ExecutionPolicy Bypass -File .\run_api_tests.ps1
 ```
 
+结果输出:
+
+```text
+tests/api_tests/reports/api_test_log.txt
+tests/api_tests/reports/api_test_summary.txt
+```
+
 ## 3. 自动化测试
 
 位置:`tests/auto_tests`
@@ -75,6 +91,15 @@ cd E:\软测\ServicePilot\tests\auto_tests
 powershell -ExecutionPolicy Bypass -File .\run_auto_tests.ps1
 ```
 
+结果输出:
+
+```text
+tests/auto_tests/reports/auto_test_log.txt
+tests/auto_tests/reports/auto_test_summary.txt
+tests/auto_tests/artifacts/*.png
+tests/auto_tests/artifacts/auto-test-result.json
+```
+
 ## 4. 性能测试
 
 位置:`tests/performance_tests`
@@ -89,7 +114,8 @@ powershell -ExecutionPolicy Bypass -File .\run_auto_tests.ps1
 需要安装 Locust:
 
 ```powershell
-pip install locust
+cd E:\软测\ServicePilot\tests\performance_tests
+pip install -r requirements.txt
 ```
 
 运行后端接口性能测试:
@@ -106,3 +132,13 @@ cd E:\软测\ServicePilot\tests\performance_tests
 powershell -ExecutionPolicy Bypass -File .\run_frontend_performance.ps1
 ```
 
+结果输出:
+
+```text
+tests/performance_tests/reports/backend-performance-report.html
+tests/performance_tests/reports/backend-performance_*.csv
+tests/performance_tests/reports/frontend-performance-report.html
+tests/performance_tests/reports/frontend-performance_*.csv
+```
+
+当前环境如未安装 Locust,脚本会生成 `reports/*_performance_pending.txt`,不伪造性能结果。

+ 17 - 0
tests/api_tests/README.md

@@ -16,9 +16,26 @@
 
 合计:5 条。
 
+## 测试步骤
+
+1. 进入接口测试目录。
+2. 执行 `run_api_tests.ps1`。
+3. 脚本自动调用后端 Jest + Supertest 测试文件。
+4. 执行完成后查看 `reports/` 下的日志和摘要。
+
 ## 运行命令
 
 ```powershell
+cd E:\软测\ServicePilot\tests\api_tests
 powershell -ExecutionPolicy Bypass -File .\run_api_tests.ps1
 ```
 
+## 验收标准
+
+| 指标 | 标准 |
+|---|---|
+| HTTP 状态码 | 与接口契约一致 |
+| 响应结构 | 字段完整、类型正确 |
+| 敏感字段 | 不暴露 `masterKey`、`restApiKey` |
+| 接口测试通过率 | 不低于 95% |
+| 输出证据 | `reports/api_test_log.txt`、`reports/api_test_summary.txt` |

+ 6 - 0
tests/api_tests/reports/README.md

@@ -0,0 +1,6 @@
+# 接口测试结果目录
+
+执行 `run_api_tests.ps1` 后生成:
+
+- `api_test_log.txt`:Jest + Supertest 原始执行日志。
+- `api_test_summary.txt`:课程报告可引用的执行摘要。

+ 15 - 0
tests/api_tests/reports/api_test_log.txt

@@ -0,0 +1,15 @@
+
+> backend@1.0.0 test
+> jest --runInBand tests/health.spec.ts tests/api-contract.spec.ts
+
+GET /api/config/parse 200 4.327 ms - 147
+GET /api/config/parse 200 1.169 ms - 147
+GET /api/unknown-resource 404 0.363 ms - 74
+POST /api/ghost 404 0.191 ms - 64
+GET /api/health 200 0.629 ms - 83
+
+Test Suites: 2 passed, 2 total
+Tests:       5 passed, 5 total
+Snapshots:   0 total
+Time:        1.887 s, estimated 2 s
+Ran all test suites matching tests/health.spec.ts|tests/api-contract.spec.ts.

+ 7 - 0
tests/api_tests/reports/api_test_summary.txt

@@ -0,0 +1,7 @@
+ServicePilot 接口测试执行记录
+执行时间:2026-06-08 16:08:07
+测试对象:project/backend/tests/health.spec.ts、project/backend/tests/api-contract.spec.ts
+测试范围:健康检查、Parse 前端配置、敏感字段保护、404 契约
+预期标准:HTTP 状态码、响应结构和错误信息符合接口契约
+执行结果:PASS
+详细日志:E:\软测\ServicePilot\tests\api_tests\reports\api_test_log.txt

+ 44 - 3
tests/api_tests/run_api_tests.ps1

@@ -1,8 +1,49 @@
-$ErrorActionPreference = "Stop"
+$ErrorActionPreference = "Stop"
 
 $projectRoot = Resolve-Path "$PSScriptRoot\..\.."
 $backendRoot = Join-Path $projectRoot "project\backend"
+$reportDir = Join-Path $PSScriptRoot "reports"
+$logFile = Join-Path $reportDir "api_test_log.txt"
+$summaryFile = Join-Path $reportDir "api_test_summary.txt"
 
-Set-Location $backendRoot
-npm.cmd test -- tests/health.spec.ts tests/api-contract.spec.ts
+New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
 
+Push-Location $backendRoot
+try {
+  $env:NO_COLOR = "1"
+  $oldErrorActionPreference = $ErrorActionPreference
+  $ErrorActionPreference = "Continue"
+  $output = & cmd.exe /d /s /c "npm.cmd test -- tests/health.spec.ts tests/api-contract.spec.ts 2>&1"
+  $exitCode = $LASTEXITCODE
+  $ErrorActionPreference = $oldErrorActionPreference
+} finally {
+  $ErrorActionPreference = "Stop"
+  Pop-Location
+}
+
+$ansiPattern = "$([char]27)\[[0-9;]*m"
+$textOutput = $output | ForEach-Object { $_.ToString() -replace $ansiPattern, "" }
+$textOutput | Set-Content -Path $logFile -Encoding UTF8
+$textOutput | ForEach-Object { Write-Host $_ }
+
+$result = "PASS"
+if ($exitCode -ne 0) {
+  $result = "FAIL"
+}
+
+@(
+  "ServicePilot 接口测试执行记录",
+  "执行时间:$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
+  "测试对象:project/backend/tests/health.spec.ts、project/backend/tests/api-contract.spec.ts",
+  "测试范围:健康检查、Parse 前端配置、敏感字段保护、404 契约",
+  "预期标准:HTTP 状态码、响应结构和错误信息符合接口契约",
+  "执行结果:$result",
+  "详细日志:$logFile"
+) | Set-Content -Path $summaryFile -Encoding UTF8
+
+Write-Host "接口测试日志已生成:$logFile"
+Write-Host "接口测试摘要已生成:$summaryFile"
+
+if ($exitCode -ne 0) {
+  exit $exitCode
+}

+ 13 - 1
tests/auto_tests/README.md

@@ -32,8 +32,20 @@ D:\nodejs\node.exe scripts\static-preview.cjs
 powershell -ExecutionPolicy Bypass -File .\run_auto_tests.ps1
 ```
 
-截图输出目录:
+## 验收标准
+
+| 指标 | 标准 |
+|---|---|
+| 页面 HTTP 状态 | 200 |
+| 覆盖页面数量 | 7 个 |
+| 页面截图 | 每个页面生成 1 张 PNG |
+| 截图文件大小 | 大于 10KB |
+| 自动化流程通过率 | 100% |
+
+## 输出证据
 
 ```text
+tests/auto_tests/reports/auto_test_log.txt
+tests/auto_tests/reports/auto_test_summary.txt
 tests/auto_tests/artifacts/
 ```

BIN
tests/auto_tests/artifacts/AUTO-001-dashboard.png


BIN
tests/auto_tests/artifacts/AUTO-002-tickets.png


BIN
tests/auto_tests/artifacts/AUTO-003-sla.png


BIN
tests/auto_tests/artifacts/AUTO-004-knowledge.png


BIN
tests/auto_tests/artifacts/AUTO-005-files.png


BIN
tests/auto_tests/artifacts/AUTO-006-reviews.png


BIN
tests/auto_tests/artifacts/AUTO-007-test-plan.png


+ 8 - 0
tests/auto_tests/reports/README.md

@@ -0,0 +1,8 @@
+# 自动化测试结果目录
+
+执行 `run_auto_tests.ps1` 后生成:
+
+- `auto_test_log.txt`:Playwright 页面访问与截图执行日志。
+- `auto_test_summary.txt`:课程报告可引用的执行摘要。
+
+页面截图和结构化 JSON 结果仍保存在 `artifacts/` 目录。

+ 21 - 0
tests/auto_tests/reports/auto_test_log.txt

@@ -0,0 +1,21 @@
+Navigating to http://127.0.0.1:4301/dashboard
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-001-dashboard.png
+AUTO-001 /dashboard PASS
+Navigating to http://127.0.0.1:4301/tickets
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-002-tickets.png
+AUTO-002 /tickets PASS
+Navigating to http://127.0.0.1:4301/sla
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-003-sla.png
+AUTO-003 /sla PASS
+Navigating to http://127.0.0.1:4301/knowledge
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-004-knowledge.png
+AUTO-004 /knowledge PASS
+Navigating to http://127.0.0.1:4301/files
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-005-files.png
+AUTO-005 /files PASS
+Navigating to http://127.0.0.1:4301/reviews
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-006-reviews.png
+AUTO-006 /reviews PASS
+Navigating to http://127.0.0.1:4301/test-plan
+Capturing screenshot into E:\软测\ServicePilot\tests\auto_tests\artifacts\AUTO-007-test-plan.png
+AUTO-007 /test-plan PASS

+ 8 - 0
tests/auto_tests/reports/auto_test_summary.txt

@@ -0,0 +1,8 @@
+ServicePilot 自动化测试执行记录
+执行时间:2026-06-08 16:09:08
+测试地址:http://127.0.0.1:4301
+测试范围:dashboard、tickets、sla、knowledge、files、reviews、test-plan 七个前端页面
+预期标准:页面 HTTP 200、截图文件生成成功、截图大小大于 10KB
+执行结果:PASS
+详细日志:E:\软测\ServicePilot\tests\auto_tests\reports\auto_test_log.txt
+截图与 JSON 结果:E:\软测\ServicePilot\tests\auto_tests\artifacts

+ 40 - 2
tests/auto_tests/run_auto_tests.ps1

@@ -1,7 +1,45 @@
-param(
+param(
   [string]$BaseUrl = "http://127.0.0.1:4301"
 )
 
 $ErrorActionPreference = "Stop"
 
-powershell -ExecutionPolicy Bypass -File "$PSScriptRoot\servicepilot-ui-flow.ps1" -BaseUrl $BaseUrl
+$reportDir = Join-Path $PSScriptRoot "reports"
+$logFile = Join-Path $reportDir "auto_test_log.txt"
+$summaryFile = Join-Path $reportDir "auto_test_summary.txt"
+
+New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
+
+$oldErrorActionPreference = $ErrorActionPreference
+$ErrorActionPreference = "Continue"
+$output = powershell -ExecutionPolicy Bypass -File "$PSScriptRoot\servicepilot-ui-flow.ps1" -BaseUrl $BaseUrl 2>&1
+$exitCode = $LASTEXITCODE
+$ErrorActionPreference = $oldErrorActionPreference
+
+$ansiPattern = "$([char]27)\[[0-9;]*m"
+$textOutput = $output | ForEach-Object { $_.ToString() -replace $ansiPattern, "" }
+$textOutput | Set-Content -Path $logFile -Encoding UTF8
+$textOutput | ForEach-Object { Write-Host $_ }
+
+$result = "PASS"
+if ($exitCode -ne 0) {
+  $result = "FAIL"
+}
+
+@(
+  "ServicePilot 自动化测试执行记录",
+  "执行时间:$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
+  "测试地址:$BaseUrl",
+  "测试范围:dashboard、tickets、sla、knowledge、files、reviews、test-plan 七个前端页面",
+  "预期标准:页面 HTTP 200、截图文件生成成功、截图大小大于 10KB",
+  "执行结果:$result",
+  "详细日志:$logFile",
+  "截图与 JSON 结果:$(Join-Path $PSScriptRoot 'artifacts')"
+) | Set-Content -Path $summaryFile -Encoding UTF8
+
+Write-Host "自动化测试日志已生成:$logFile"
+Write-Host "自动化测试摘要已生成:$summaryFile"
+
+if ($exitCode -ne 0) {
+  exit $exitCode
+}

+ 17 - 0
tests/performance_tests/README.md

@@ -13,6 +13,13 @@
 
 ## 运行命令
 
+安装依赖:
+
+```powershell
+cd E:\软测\ServicePilot\tests\performance_tests
+pip install -r requirements.txt
+```
+
 后端性能测试:
 
 ```powershell
@@ -34,3 +41,13 @@ powershell -ExecutionPolicy Bypass -File .\run_frontend_performance.ps1
 | 错误率 | < 1% |
 | 服务稳定性 | 压测期间不崩溃 |
 
+## 输出证据
+
+```text
+tests/performance_tests/reports/backend-performance-report.html
+tests/performance_tests/reports/backend-performance_*.csv
+tests/performance_tests/reports/frontend-performance-report.html
+tests/performance_tests/reports/frontend-performance_*.csv
+```
+
+如果未安装 Locust,运行脚本会生成 `reports/*_performance_pending.txt`,用于说明未执行原因和补跑命令。

+ 10 - 0
tests/performance_tests/reports/README.md

@@ -0,0 +1,10 @@
+# 性能测试结果目录
+
+执行 Locust 脚本后生成:
+
+- `backend-performance-report.html`:后端接口性能测试 HTML 报告。
+- `backend-performance_*.csv`:后端接口性能测试 CSV 明细。
+- `frontend-performance-report.html`:前端页面性能测试 HTML 报告。
+- `frontend-performance_*.csv`:前端页面性能测试 CSV 明细。
+
+如果当前环境未安装 Locust,运行脚本会生成 `*_performance_pending.txt`,用于说明待执行原因和补跑命令。

+ 5 - 0
tests/performance_tests/reports/backend_performance_pending.txt

@@ -0,0 +1,5 @@
+ServicePilot 后端性能测试未执行
+原因:当前环境未安装 Locust 命令。
+安装命令:pip install -r requirements.txt
+执行命令:powershell -ExecutionPolicy Bypass -File .\run_backend_performance.ps1
+预期输出:reports/backend-performance-report.html 与 reports/backend-performance_*.csv

+ 5 - 0
tests/performance_tests/reports/frontend_performance_pending.txt

@@ -0,0 +1,5 @@
+ServicePilot 前端性能测试未执行
+原因:当前环境未安装 Locust 命令。
+安装命令:pip install -r requirements.txt
+执行命令:powershell -ExecutionPolicy Bypass -File .\run_frontend_performance.ps1
+预期输出:reports/frontend-performance-report.html 与 reports/frontend-performance_*.csv

+ 1 - 0
tests/performance_tests/requirements.txt

@@ -0,0 +1 @@
+locust>=2.24.0

+ 24 - 4
tests/performance_tests/run_backend_performance.ps1

@@ -1,10 +1,30 @@
-$ErrorActionPreference = "Stop"
+$ErrorActionPreference = "Stop"
 
-locust -f "$PSScriptRoot\locustfile_backend.py" `
+$reportDir = Join-Path $PSScriptRoot "reports"
+$htmlReport = Join-Path $reportDir "backend-performance-report.html"
+$csvPrefix = Join-Path $reportDir "backend-performance"
+$pendingFile = Join-Path $reportDir "backend_performance_pending.txt"
+
+New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
+
+$locust = Get-Command locust -ErrorAction SilentlyContinue
+if ($null -eq $locust) {
+  @(
+    "ServicePilot 后端性能测试未执行",
+    "原因:当前环境未安装 Locust 命令。",
+    "安装命令:pip install -r requirements.txt",
+    "执行命令:powershell -ExecutionPolicy Bypass -File .\run_backend_performance.ps1",
+    "预期输出:reports/backend-performance-report.html 与 reports/backend-performance_*.csv"
+  ) | Set-Content -Path $pendingFile -Encoding UTF8
+  Write-Host "Locust 未安装,已生成待执行说明:$pendingFile"
+  exit 1
+}
+
+& $locust.Source -f "$PSScriptRoot\locustfile_backend.py" `
   --host "http://localhost:3000" `
   --headless `
   -u 30 `
   -r 5 `
   -t 3m `
-  --html "$PSScriptRoot\backend-performance-report.html"
-
+  --html "$htmlReport" `
+  --csv "$csvPrefix"

+ 24 - 4
tests/performance_tests/run_frontend_performance.ps1

@@ -1,10 +1,30 @@
-$ErrorActionPreference = "Stop"
+$ErrorActionPreference = "Stop"
 
-locust -f "$PSScriptRoot\locustfile_frontend.py" `
+$reportDir = Join-Path $PSScriptRoot "reports"
+$htmlReport = Join-Path $reportDir "frontend-performance-report.html"
+$csvPrefix = Join-Path $reportDir "frontend-performance"
+$pendingFile = Join-Path $reportDir "frontend_performance_pending.txt"
+
+New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
+
+$locust = Get-Command locust -ErrorAction SilentlyContinue
+if ($null -eq $locust) {
+  @(
+    "ServicePilot 前端性能测试未执行",
+    "原因:当前环境未安装 Locust 命令。",
+    "安装命令:pip install -r requirements.txt",
+    "执行命令:powershell -ExecutionPolicy Bypass -File .\run_frontend_performance.ps1",
+    "预期输出:reports/frontend-performance-report.html 与 reports/frontend-performance_*.csv"
+  ) | Set-Content -Path $pendingFile -Encoding UTF8
+  Write-Host "Locust 未安装,已生成待执行说明:$pendingFile"
+  exit 1
+}
+
+& $locust.Source -f "$PSScriptRoot\locustfile_frontend.py" `
   --host "http://127.0.0.1:4301" `
   --headless `
   -u 30 `
   -r 5 `
   -t 3m `
-  --html "$PSScriptRoot\frontend-performance-report.html"
-
+  --html "$htmlReport" `
+  --csv "$csvPrefix"

+ 16 - 0
tests/unit_tests/README.md

@@ -15,9 +15,25 @@
 
 合计:26 条。
 
+## 测试步骤
+
+1. 进入单元测试目录。
+2. 执行 `run_unit_tests.ps1`。
+3. 脚本自动调用后端 Jest 测试文件 `project/backend/tests/quality-rules.spec.ts`。
+4. 执行完成后查看 `reports/` 下的日志和摘要。
+
 ## 运行命令
 
 ```powershell
+cd E:\软测\ServicePilot\tests\unit_tests
 powershell -ExecutionPolicy Bypass -File .\run_unit_tests.ps1
 ```
 
+## 验收标准
+
+| 指标 | 标准 |
+|---|---|
+| 核心业务规则 | 100% 通过 |
+| 单元测试整体通过率 | 不低于 95% |
+| 阻塞缺陷 | 0 个 |
+| 输出证据 | `reports/unit_test_log.txt`、`reports/unit_test_summary.txt` |

+ 6 - 0
tests/unit_tests/reports/README.md

@@ -0,0 +1,6 @@
+# 单元测试结果目录
+
+执行 `run_unit_tests.ps1` 后生成:
+
+- `unit_test_log.txt`:Jest 原始执行日志。
+- `unit_test_summary.txt`:课程报告可引用的执行摘要。

+ 9 - 0
tests/unit_tests/reports/unit_test_log.txt

@@ -0,0 +1,9 @@
+
+> backend@1.0.0 test
+> jest --runInBand tests/quality-rules.spec.ts
+
+Test Suites: 1 passed, 1 total
+Tests:       26 passed, 26 total
+Snapshots:   0 total
+Time:        0.814 s, estimated 1 s
+Ran all test suites matching tests/quality-rules.spec.ts.

+ 7 - 0
tests/unit_tests/reports/unit_test_summary.txt

@@ -0,0 +1,7 @@
+ServicePilot 单元测试执行记录
+执行时间:2026-06-08 16:08:05
+测试对象:project/backend/tests/quality-rules.spec.ts
+测试范围:工单状态流转、用户权限隔离、SLA 判断、附件规则
+预期标准:核心业务规则通过率 100%,整体用例通过率不低于 95%
+执行结果:PASS
+详细日志:E:\软测\ServicePilot\tests\unit_tests\reports\unit_test_log.txt

+ 44 - 3
tests/unit_tests/run_unit_tests.ps1

@@ -1,8 +1,49 @@
-$ErrorActionPreference = "Stop"
+$ErrorActionPreference = "Stop"
 
 $projectRoot = Resolve-Path "$PSScriptRoot\..\.."
 $backendRoot = Join-Path $projectRoot "project\backend"
+$reportDir = Join-Path $PSScriptRoot "reports"
+$logFile = Join-Path $reportDir "unit_test_log.txt"
+$summaryFile = Join-Path $reportDir "unit_test_summary.txt"
 
-Set-Location $backendRoot
-npm.cmd test -- tests/quality-rules.spec.ts
+New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
 
+Push-Location $backendRoot
+try {
+  $env:NO_COLOR = "1"
+  $oldErrorActionPreference = $ErrorActionPreference
+  $ErrorActionPreference = "Continue"
+  $output = & cmd.exe /d /s /c "npm.cmd test -- tests/quality-rules.spec.ts 2>&1"
+  $exitCode = $LASTEXITCODE
+  $ErrorActionPreference = $oldErrorActionPreference
+} finally {
+  $ErrorActionPreference = "Stop"
+  Pop-Location
+}
+
+$ansiPattern = "$([char]27)\[[0-9;]*m"
+$textOutput = $output | ForEach-Object { $_.ToString() -replace $ansiPattern, "" }
+$textOutput | Set-Content -Path $logFile -Encoding UTF8
+$textOutput | ForEach-Object { Write-Host $_ }
+
+$result = "PASS"
+if ($exitCode -ne 0) {
+  $result = "FAIL"
+}
+
+@(
+  "ServicePilot 单元测试执行记录",
+  "执行时间:$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
+  "测试对象:project/backend/tests/quality-rules.spec.ts",
+  "测试范围:工单状态流转、用户权限隔离、SLA 判断、附件规则",
+  "预期标准:核心业务规则通过率 100%,整体用例通过率不低于 95%",
+  "执行结果:$result",
+  "详细日志:$logFile"
+) | Set-Content -Path $summaryFile -Encoding UTF8
+
+Write-Host "单元测试日志已生成:$logFile"
+Write-Host "单元测试摘要已生成:$summaryFile"
+
+if ($exitCode -ne 0) {
+  exit $exitCode
+}

+ 17 - 0
tests/提交结构说明.md

@@ -0,0 +1,17 @@
+# ServicePilot 四类测试提交结构说明
+
+本目录按历史实训作业的交付方式整理,每一类测试都作为一个独立测试单元提交,包含测试脚本、运行入口、结果证据和说明文档。
+
+| 测试单元 | 目录 | 脚本入口 | 结果证据 |
+|---|---|---|---|
+| 单元测试 | `unit_tests/` | `run_unit_tests.ps1` | `reports/unit_test_log.txt`、`reports/unit_test_summary.txt` |
+| 接口测试 | `api_tests/` | `run_api_tests.ps1` | `reports/api_test_log.txt`、`reports/api_test_summary.txt` |
+| 自动化测试 | `auto_tests/` | `run_auto_tests.ps1` | `reports/auto_test_log.txt`、`artifacts/*.png`、`artifacts/auto-test-result.json` |
+| 性能测试 | `performance_tests/` | `run_backend_performance.ps1`、`run_frontend_performance.ps1` | `reports/*.html`、`reports/*.csv` 或 `reports/*_performance_pending.txt` |
+
+## 提交口径
+
+1. 每类测试目录独立保留 README,说明测试目标、范围、步骤和验收标准。
+2. 可直接运行的测试使用 PowerShell 脚本作为统一入口,避免手动拼接命令。
+3. 已执行的测试保留日志、摘要、截图或 JSON 结果,方便报告引用。
+4. 性能测试不伪造结果;未安装 Locust 时只保留脚本、依赖文件和待执行说明。

+ 30 - 2
tests/测试结果汇总.md

@@ -19,6 +19,13 @@ powershell -ExecutionPolicy Bypass -File .\run_unit_tests.ps1
 | 通过率 | 100% |
 | 结论 | 通过 |
 
+结果证据:
+
+```text
+tests/unit_tests/reports/unit_test_log.txt
+tests/unit_tests/reports/unit_test_summary.txt
+```
+
 覆盖内容:
 
 - 工单状态流转
@@ -45,6 +52,13 @@ powershell -ExecutionPolicy Bypass -File .\run_api_tests.ps1
 | 通过率 | 100% |
 | 结论 | 通过 |
 
+结果证据:
+
+```text
+tests/api_tests/reports/api_test_log.txt
+tests/api_tests/reports/api_test_summary.txt
+```
+
 覆盖接口:
 
 - `GET /api/health`
@@ -72,6 +86,14 @@ powershell -ExecutionPolicy Bypass -File .\run_auto_tests.ps1
 | 通过率 | 100% |
 | 结论 | 通过 |
 
+结果证据:
+
+```text
+tests/auto_tests/reports/auto_test_log.txt
+tests/auto_tests/reports/auto_test_summary.txt
+tests/auto_tests/artifacts/
+```
+
 覆盖页面:
 
 | 编号 | 页面 | 结果 |
@@ -110,11 +132,17 @@ tests/auto_tests/artifacts/
 | 前端性能测试 | 待安装 Locust 后执行 |
 | HTML 报告 | 执行脚本后自动生成 |
 
+结果证据:
+
+```text
+tests/performance_tests/requirements.txt
+tests/performance_tests/reports/README.md
+```
+
 建议执行命令:
 
 ```powershell
-pip install locust
+pip install -r requirements.txt
 powershell -ExecutionPolicy Bypass -File .\run_backend_performance.ps1
 powershell -ExecutionPolicy Bypass -File .\run_frontend_performance.ps1
 ```
-