mcpField
T
test-case-designer

test-case-designer

github.com/masanao-ohba测试与质量241 次安装32 周前更新
代码仓库

关于 test-case-designer

用于围绕 PHP/CakePHP 应用的需求与功能设计测试用例的技能,涵盖测试层级、常用设计方法、优先级划分和测试文档。

主要功能

  1. 01按需求组织测试用例
  2. 02设计单元、集成和系统测试
  3. 03运用边界值与等价类分析
  4. 04建模状态转换
  5. 05按风险确定测试优先级
  6. 06编写 CakePHP 测试设计

适用场景

  1. 01为新应用功能规划测试
  2. 02识别边界情况和异常路径
  3. 03确定认证或支付测试的优先级
  4. 04创建测试设计文档

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/masanao-ohba/claude-manifests --skill test-case-designer

安装后在 Claude Code 中输入/test-case-designer确认已加载。

详细介绍

测试用例设计师

一项专门用于为 PHP/CakePHP 应用设计测试用例的技能,确保全面覆盖需求和功能。

核心职责

1. 测试用例结构

标准测试用例格式:

Test Case:
  id: TC-[number]
  requirement_id: REQ-[number]
  type: unit|integration|system|e2e
  priority: high|medium|low

  description: [What is being tested]

  preconditions:
    - [Required setup]
    - [Initial state]

  test_steps:
    1. [Action to perform]
    2. [Next action]

  expected_results:
    - [Expected outcome]
    - [Verification point]

  postconditions:
    - [Cleanup needed]
    - [State after test]

  test_data:
    - [Required test data]
2. 测试分类

单元测试:

/**
 * 単体テスト設計
 *
 * 対象: Individual methods/functions
 * 目的: Logic verification in isolation
 * モック: External dependencies
 */
Unit Test Criteria:
  - Single class/method focus
  - No database access
  - No external API calls
  - Fast execution (< 100ms)
  - Deterministic results

集成测试:

/**
 * 結合テスト設計
 *
 * 対象: Component interactions
 * 目的: Verify integrations work
 * 実行: With real dependencies
 */
Integration Test Criteria:
  - Multiple components
  - Database interactions
  - Service integrations
  - Realistic scenarios

系统测试:

/**
 * システムテスト設計
 *
 * 対象: End-to-end workflows
 * 目的: Full feature validation
 * 環境: Production-like
 */
System Test Criteria:
  - Complete user workflows
  - All components integrated
  - Performance validation
  - Security verification
3. CakePHP 测试格式

PHPUnit 测试结构:

/**
 * [機能名]のテスト
 *
 * 保証対象:
 * 1. [具体的な保証内容1]
 * 2. [具体的な保証内容2]
 * 失敗時の損失:
 * - [ビジネスへの影響]
 * - [ユーザーへの影響]
 */
public function test[MethodName](): void
{
    // Arrange (準備)
    // テストデータのセットアップ

    // Act (実行)
    // テスト対象の実行

    // Assert (検証)
    // 結果の確認
}
4. 测试用例设计模式

边界值分析:

Input: age (1-120)
Test Cases:
  - TC-001: age = 0 (below minimum)
  - TC-002: age = 1 (minimum)
  - TC-003: age = 60 (typical)
  - TC-004: age = 120 (maximum)
  - TC-005: age = 121 (above maximum)

等价类划分:

Input: user_type
Partitions:
  - admin: Full access
  - user: Limited access
  - guest: Read-only

Test Cases:
  - TC-001: Admin can delete
  - TC-002: User cannot delete
  - TC-003: Guest cannot modify

状态转换:

States: draft → submitted → approved → completed

Test Cases:
  - TC-001: draft to submitted (valid)
  - TC-002: draft to approved (invalid)
  - TC-003: approved to submitted (invalid)
  - TC-004: approved to completed (valid)
5. 测试文档模板
# Test Design Document: [Feature]

## Test Scope
### In Scope
- [What will be tested]

### Out of Scope
- [What won't be tested]

## Test Strategy
### Unit Tests
| Test ID | Description | Type | Priority |
|---------|-------------|------|----------|
| UT-001 | Validate email format | Unit | High |
| UT-002 | Calculate order total | Unit | High |

### Integration Tests
| Test ID | Description | Components | Priority |
|---------|-------------|------------|----------|
| IT-001 | User login flow | Auth + DB | High |
| IT-002 | Order processing | Order + Payment | High |

### System Tests
| Test ID | Description | Workflow | Priority |
|---------|-------------|----------|----------|
| ST-001 | Complete purchase | End-to-end | High |
| ST-002 | User registration | Full flow | Medium |

## Test Data Requirements
### Database State
- Users: 10 test users with various roles
- Products: 50 test products
- Orders: 100 test orders in various states

### Test Fixtures
```php
protected $fixtures = [
    'app.Users',
    'app.Products',
    'app.Orders',
    'app.OrderItems'
];

基于风险的测试

高风险区域
  • 支付处理
  • 用户身份验证
  • 数据安全
中风险区域
  • 报告功能
  • 邮件通知
低风险区域
  • 静态内容显示
  • 帮助文档

## Test Case Generation Process

### Step 1: Requirement Analysis

对于每项需求:

  1. 确定可测试条件
  2. 确定所需的测试类型
  3. 定义成功标准
  4. 确定边界情况

### Step 2: Test Case Creation

对于每个条件:

  1. 创建正向测试用例(正常流程)
  2. 创建负向测试用例(错误流程)
  3. 创建边界测试用例
  4. 创建性能测试用例(如适用)

### Step 3: Test Data Design

对于每个测试用例:

  1. 定义输入数据
  2. 定义预期输出
  3. 定义数据库状态
  4. 定义外部依赖项

### Step 4: Test Prioritization

优先级矩阵: 影响 高 低 风险 高 P1 P2 低 P2 P3

P1:必须测试(阻塞性) P2:应该测试(重要) P3:可以测试(锦上添花)


## CakePHP Specific Test Cases

### Controller Tests
```php
/**
 * Controller action test template
 */
public function testIndex(): void
{
    // 保証対象1: 認証が必要
    $this->get('/users');
    $this->assertRedirect('/login');

    // 保証対象2: 認証後アクセス可能
    $this->session(['Auth.User.id' => 1]);
    $this->get('/users');
    $this->assertResponseOk();

    // 保証対象3: データ表示
    $this->assertResponseContains('User List');
}
模型测试
/**
 * Model validation test template
 */
public function testValidation(): void
{
    // 保証対象1: 必須フィールド
    $user = $this->Users->newEmptyEntity();
    $user = $this->Users->patchEntity($user, []);
    $this->assertFalse($this->Users->save($user));
    $this->assertNotEmpty($user->getErrors());

    // 保証対象2: 正常データ
    $user = $this->Users->patchEntity($user, [
        'email' => '[email protected]',
        'password' => 'SecurePass123'
    ]);
    $this->assertTrue($this->Users->save($user));
}
组件测试
/**
 * Component behavior test template
 */
public function testComponentMethod(): void
{
    // 保証対象1: 正常系
    $result = $this->Component->process($validData);
    $this->assertTrue($result);

    // 保証対象2: 異常系
    $result = $this->Component->process($invalidData);
    $this->assertFalse($result);
}

测试覆盖率标准

代码覆盖率目标
Minimum Coverage:
  - Unit Tests: 80%
  - Integration Tests: 60%
  - Overall: 70%

Critical Components:
  - Authentication: 95%
  - Payment Processing: 95%
  - Data Validation: 90%
需求覆盖率
Functional Requirements:
  - All MUST requirements: 100%
  - All SHOULD requirements: 80%
  - All COULD requirements: 50%

Non-Functional Requirements:
  - Performance: All critical paths
  - Security: All auth points
  - Usability: Key workflows

输出示例

示例 1:登录测试设计
Test Suite: User Authentication

Unit Tests:
  - UT-001: Password hashing algorithm
  - UT-002: Token generation
  - UT-003: Session validation

Integration Tests:
  - IT-001: Database authentication
  - IT-002: LDAP authentication
  - IT-003: OAuth authentication

System Tests:
  - ST-001: Complete login flow
  - ST-002: Password reset flow
  - ST-003: Two-factor authentication
示例 2:订单处理测试设计
Test Suite: Order Management

Unit Tests:
  - UT-001: Calculate item total
  - UT-002: Apply discount rules
  - UT-003: Validate inventory

Integration Tests:
  - IT-001: Create order with payment
  - IT-002: Update inventory on order
  - IT-003: Send order notifications

System Tests:
  - ST-001: Complete purchase workflow
  - ST-002: Order cancellation workflow
  - ST-003: Return/refund workflow

最佳实践

  1. 尽早测试:结合需求设计测试
  2. 测试独立性:每项测试都应可独立运行
  3. 命名清晰:测试名称应说明测试内容
  4. 单一断言:每项测试只做一项逻辑断言
  5. 快速反馈:优先安排运行速度快的测试
  6. 易于维护:保持测试简单、易读

请记住:良好的测试设计能在 Bug 进入生产环境前将其捕获。

评论

支持 Markdown