pict-test-designer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PICT Test Designer

PICT测试用例设计工具

This skill enables systematic test case design using PICT (Pairwise Independent Combinatorial Testing). Given requirements or code, it analyzes the system to identify test parameters, generates a PICT model with appropriate constraints, executes the model to generate pairwise test cases, and formats the results with expected outputs.
本技能支持使用PICT(Pairwise Independent Combinatorial Testing)进行系统化的测试用例设计。给定需求或代码,它会分析系统以识别测试参数,生成带有适当约束的PICT模型,执行模型以生成成对测试用例,并格式化输出结果及预期输出。

When to Use This Skill

何时使用本技能

Use this skill when:
  • Designing test cases for a feature, function, or system with multiple input parameters
  • Creating test suites for configurations with many combinations
  • Needing comprehensive coverage with minimal test cases
  • Analyzing requirements to identify test scenarios
  • Working with code that has multiple conditional paths
  • Building test matrices for API endpoints, web forms, or system configurations
在以下场景使用本技能:
  • 为具有多个输入参数的功能、函数或系统设计测试用例
  • 为包含大量组合的配置创建测试套件
  • 需要以最少的测试用例实现全面覆盖
  • 分析需求以识别测试场景
  • 处理包含多个条件分支的代码
  • 为API接口、Web表单或系统配置构建测试矩阵

Workflow

工作流程

Follow this process for test design:
遵循以下流程进行测试设计:

1. Analyze Requirements or Code

1. 分析需求或代码

From the user's requirements or code, identify:
  • Parameters: Input variables, configuration options, environmental factors
  • Values: Possible values for each parameter (using equivalence partitioning)
  • Constraints: Business rules, technical limitations, dependencies between parameters
  • Expected Outcomes: What should happen for different combinations
Example Analysis:
For a login function with requirements:
  • Users can login with username/password
  • Supports 2FA (on/off)
  • Remembers login on trusted devices
  • Rate limits after 3 failed attempts
Identified parameters:
  • Credentials: Valid, Invalid
  • TwoFactorAuth: Enabled, Disabled
  • RememberMe: Checked, Unchecked
  • PreviousFailures: 0, 1, 2, 3, 4
从用户的需求或代码中,识别:
  • 参数:输入变量、配置选项、环境因素
  • 取值:每个参数的可能取值(使用等价类划分)
  • 约束:业务规则、技术限制、参数间的依赖关系
  • 预期结果:不同组合下应出现的结果
分析示例:
针对一个登录功能,需求如下:
  • 用户可通过用户名/密码登录
  • 支持2FA(开启/关闭)
  • 在可信设备上记住登录状态
  • 3次失败尝试后触发速率限制
识别出的参数:
  • Credentials: Valid, Invalid
  • TwoFactorAuth: Enabled, Disabled
  • RememberMe: Checked, Unchecked
  • PreviousFailures: 0, 1, 2, 3, 4

2. Generate PICT Model

2. 生成PICT模型

Create a PICT model with:
  • Clear parameter names
  • Well-defined value sets (using equivalence partitioning and boundary values)
  • Constraints for invalid combinations
  • Comments explaining business rules
Model Structure:
undefined
创建包含以下内容的PICT模型:
  • 清晰的参数名称
  • 定义明确的取值集合(使用等价类划分和边界值)
  • 无效组合的约束
  • 解释业务规则的注释
模型结构:
undefined

Parameter definitions

Parameter definitions

ParameterName: Value1, Value2, Value3
ParameterName: Value1, Value2, Value3

Constraints (if any)

Constraints (if any)

IF [Parameter1] = "Value" THEN [Parameter2] <> "OtherValue";

**Refer to docs/pict_syntax.md for:**
- Complete syntax reference
- Constraint grammar and operators
- Advanced features (sub-models, aliasing, negative testing)
- Command-line options
- Detailed constraint patterns

**Refer to docs/examples.md for:**
- Complete real-world examples by domain
- Software function testing examples
- Web application, API, and mobile testing examples
- Database and configuration testing patterns
- Common patterns for authentication, resource access, error handling
IF [Parameter1] = "Value" THEN [Parameter2] <> "OtherValue";

**参考docs/pict_syntax.md获取:**
- 完整的语法参考
- 约束语法和运算符
- 高级功能(子模型、别名、负面测试)
- 命令行选项
- 详细的约束模式

**参考docs/examples.md获取:**
- 按领域分类的完整真实示例
- 软件功能测试示例
- Web应用、API和移动测试示例
- 数据库和配置测试模式
- 认证、资源访问、错误处理的常见模式

3. Execute PICT Model

3. 执行PICT模型

Generate the PICT model text and format it for the user. You can use Python code directly to work with the model:
python
undefined
生成PICT模型文本并为用户格式化。你可以直接使用Python代码处理模型:
python
undefined

Define parameters and constraints

Define parameters and constraints

parameters = { "OS": ["Windows", "Linux", "MacOS"], "Browser": ["Chrome", "Firefox", "Safari"], "Memory": ["4GB", "8GB", "16GB"] }
constraints = [ 'IF [OS] = "MacOS" THEN [Browser] IN {Safari, Chrome}', 'IF [Memory] = "4GB" THEN [OS] <> "MacOS"' ]
parameters = { "OS": ["Windows", "Linux", "MacOS"], "Browser": ["Chrome", "Firefox", "Safari"], "Memory": ["4GB", "8GB", "16GB"] }
constraints = [ 'IF [OS] = "MacOS" THEN [Browser] IN {Safari, Chrome}', 'IF [Memory] = "4GB" THEN [OS] <> "MacOS"' ]

Generate model text

Generate model text

model_lines = [] for param_name, values in parameters.items(): values_str = ", ".join(values) model_lines.append(f"{param_name}: {values_str}")
if constraints: model_lines.append("") for constraint in constraints: if not constraint.endswith(';'): constraint += ';' model_lines.append(constraint)
model_text = "\n".join(model_lines) print(model_text)

**Using the helper script (optional):**
The `scripts/pict_helper.py` script provides utilities for model generation and output formatting:

```bash
model_lines = [] for param_name, values in parameters.items(): values_str = ", ".join(values) model_lines.append(f"{param_name}: {values_str}")
if constraints: model_lines.append("") for constraint in constraints: if not constraint.endswith(';'): constraint += ';' model_lines.append(constraint)
model_text = "\n".join(model_lines) print(model_text)

**使用辅助脚本(可选):**
`scripts/pict_helper.py`脚本提供了模型生成和输出格式化的工具:

```bash

Generate model from JSON config

Generate model from JSON config

python scripts/pict_helper.py generate config.json
python scripts/pict_helper.py generate config.json

Format PICT tool output as markdown table

Format PICT tool output as markdown table

python scripts/pict_helper.py format output.txt
python scripts/pict_helper.py format output.txt

Parse PICT output to JSON

Parse PICT output to JSON

python scripts/pict_helper.py parse output.txt

**To generate actual test cases**, the user can:
1. Save the PICT model to a file (e.g., `model.txt`)
2. Use online PICT tools like:
   - https://pairwise.yuuniworks.com/
   - https://pairwise.teremokgames.com/
3. Or install PICT locally (see docs/pict_syntax.md)
python scripts/pict_helper.py parse output.txt

**要生成实际的测试用例**,用户可以:
1. 将PICT模型保存到文件中(例如:`model.txt`)
2. 使用在线PICT工具,如:
   - https://pairwise.yuuniworks.com/
   - https://pairwise.teremokgames.com/
3. 或在本地安装PICT(参考docs/pict_syntax.md)

4. Determine Expected Outputs

4. 确定预期输出

For each generated test case, determine the expected outcome based on:
  • Business requirements
  • Code logic
  • Valid/invalid combinations
Create a list of expected outputs corresponding to each test case.
针对每个生成的测试用例,根据以下内容确定预期结果:
  • 业务需求
  • 代码逻辑
  • 有效/无效组合
创建与每个测试用例对应的预期输出列表。

5. Format Complete Test Suite

5. 格式化完整测试套件

Provide the user with:
  1. PICT Model - The complete model with parameters and constraints
  2. Markdown Table - Test cases in table format with test numbers
  3. Expected Outputs - Expected result for each test case
为用户提供以下内容:
  1. PICT模型 - 包含参数和约束的完整模型
  2. Markdown表格 - 带测试编号的表格格式测试用例
  3. 预期输出 - 每个测试用例的预期结果

Output Format

输出格式

Present results in this structure:
markdown
undefined
按以下结构呈现结果:
markdown
undefined

PICT Model

PICT模型

undefined
undefined

Parameters

Parameters

Parameter1: Value1, Value2, Value3 Parameter2: ValueA, ValueB
Parameter1: Value1, Value2, Value3 Parameter2: ValueA, ValueB

Constraints

Constraints

IF [Parameter1] = "Value1" THEN [Parameter2] = "ValueA";
undefined
IF [Parameter1] = "Value1" THEN [Parameter2] = "ValueA";
undefined

Generated Test Cases

生成的测试用例

Test #Parameter1Parameter2Expected Output
1Value1ValueASuccess
2Value2ValueBSuccess
3Value1ValueBError: Invalid combination
...
测试编号Parameter1Parameter2预期输出
1Value1ValueA成功
2Value2ValueB成功
3Value1ValueB错误:无效组合
...

Test Case Summary

测试用例摘要

  • Total test cases: N
  • Coverage: Pairwise (all 2-way combinations)
  • Constraints applied: N
undefined
  • 总测试用例数:N
  • 覆盖范围:成对测试(所有双向组合)
  • 应用的约束数:N
undefined

Best Practices

最佳实践

Parameter Identification

参数识别

Good:
  • Use descriptive names:
    AuthMethod
    ,
    UserRole
    ,
    PaymentType
  • Apply equivalence partitioning:
    FileSize: Small, Medium, Large
    instead of
    FileSize: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • Include boundary values:
    Age: 0, 17, 18, 65, 66
  • Add negative values for error testing:
    Amount: ~-1, 0, 100, ~999999
Avoid:
  • Generic names:
    Param1
    ,
    Value1
    ,
    V1
  • Too many values without partitioning
  • Missing edge cases
推荐做法:
  • 使用描述性名称:
    AuthMethod
    ,
    UserRole
    ,
    PaymentType
  • 应用等价类划分:
    FileSize: Small, Medium, Large
    而非
    FileSize: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • 包含边界值:
    Age: 0, 17, 18, 65, 66
  • 添加负面测试的取值:
    Amount: ~-1, 0, 100, ~999999
避免做法:
  • 通用名称:
    Param1
    ,
    Value1
    ,
    V1
  • 未划分的过多取值
  • 遗漏边缘场景

Constraint Writing

约束编写

Good:
  • Document rationale:
    # Safari only available on MacOS
  • Start simple, add incrementally
  • Test constraints work as expected
Avoid:
  • Over-constraining (eliminates too many valid combinations)
  • Under-constraining (generates invalid test cases)
  • Complex nested logic without clear documentation
推荐做法:
  • 记录理由:
    # Safari仅在MacOS上可用
  • 从简单开始,逐步添加
  • 测试约束是否按预期工作
避免做法:
  • 过度约束(排除过多有效组合)
  • 约束不足(生成无效测试用例)
  • 无清晰文档的复杂嵌套逻辑

Expected Output Definition

预期输出定义

Be specific:
  • "Login succeeds, user redirected to dashboard"
  • "HTTP 400: Invalid credentials error"
  • "2FA prompt displayed"
Not vague:
  • "Works"
  • "Error"
  • "Success"
要具体:
  • "登录成功,用户重定向至仪表盘"
  • "HTTP 400:无效凭证错误"
  • "显示2FA提示"
避免模糊:
  • "可用"
  • "错误"
  • "成功"

Scalability

可扩展性

For large parameter sets:
  • Use sub-models to group related parameters with different orders
  • Consider separate test suites for unrelated features
  • Start with order 2 (pairwise), increase for critical combinations
  • Typical pairwise testing reduces test cases by 80-90% vs exhaustive
针对大型参数集:
  • 使用子模型对相关参数进行分组,设置不同的组合阶数
  • 考虑为不相关的功能创建单独的测试套件
  • 从2阶(成对)开始,针对关键组合提高阶数
  • 典型的成对测试相比 exhaustive(穷尽)测试可减少80-90%的测试用例

Common Patterns

常见模式

Web Form Testing

Web表单测试

python
parameters = {
    "Name": ["Valid", "Empty", "TooLong"],
    "Email": ["Valid", "Invalid", "Empty"],
    "Password": ["Strong", "Weak", "Empty"],
    "Terms": ["Accepted", "NotAccepted"]
}

constraints = [
    'IF [Terms] = "NotAccepted" THEN [Name] = "Valid"',  # Test validation even if terms not accepted
]
python
parameters = {
    "Name": ["Valid", "Empty", "TooLong"],
    "Email": ["Valid", "Invalid", "Empty"],
    "Password": ["Strong", "Weak", "Empty"],
    "Terms": ["Accepted", "NotAccepted"]
}

constraints = [
    'IF [Terms] = "NotAccepted" THEN [Name] = "Valid"',  # 即使未接受条款也要测试验证逻辑
]

API Endpoint Testing

API接口测试

python
parameters = {
    "HTTPMethod": ["GET", "POST", "PUT", "DELETE"],
    "Authentication": ["Valid", "Invalid", "Missing"],
    "ContentType": ["JSON", "XML", "FormData"],
    "PayloadSize": ["Empty", "Small", "Large"]
}

constraints = [
    'IF [HTTPMethod] = "GET" THEN [PayloadSize] = "Empty"',
    'IF [Authentication] = "Missing" THEN [HTTPMethod] IN {GET, POST}'
]
python
parameters = {
    "HTTPMethod": ["GET", "POST", "PUT", "DELETE"],
    "Authentication": ["Valid", "Invalid", "Missing"],
    "ContentType": ["JSON", "XML", "FormData"],
    "PayloadSize": ["Empty", "Small", "Large"]
}

constraints = [
    'IF [HTTPMethod] = "GET" THEN [PayloadSize] = "Empty"',
    'IF [Authentication] = "Missing" THEN [HTTPMethod] IN {GET, POST}'
]

Configuration Testing

配置测试

python
parameters = {
    "Environment": ["Dev", "Staging", "Production"],
    "CacheEnabled": ["True", "False"],
    "LogLevel": ["Debug", "Info", "Error"],
    "Database": ["SQLite", "PostgreSQL", "MySQL"]
}

constraints = [
    'IF [Environment] = "Production" THEN [LogLevel] <> "Debug"',
    'IF [Database] = "SQLite" THEN [Environment] = "Dev"'
]
python
parameters = {
    "Environment": ["Dev", "Staging", "Production"],
    "CacheEnabled": ["True", "False"],
    "LogLevel": ["Debug", "Info", "Error"],
    "Database": ["SQLite", "PostgreSQL", "MySQL"]
}

constraints = [
    'IF [Environment] = "Production" THEN [LogLevel] <> "Debug"',
    'IF [Database] = "SQLite" THEN [Environment] = "Dev"'
]

Troubleshooting

故障排除

No Test Cases Generated

未生成测试用例

  • Check constraints aren't over-restrictive
  • Verify constraint syntax (must end with
    ;
    )
  • Ensure parameter names in constraints match definitions (use
    [ParameterName]
    )
  • 检查约束是否过度限制
  • 验证约束语法(必须以
    ;
    结尾)
  • 确保约束中的参数名称与定义匹配(使用
    [ParameterName]

Too Many Test Cases

测试用例过多

  • Verify using order 2 (pairwise) not higher order
  • Consider breaking into sub-models
  • Check if parameters can be separated into independent test suites
  • 确认使用的是2阶(成对)而非更高阶
  • 考虑拆分为子模型
  • 检查参数是否可分离为独立的测试套件

Invalid Combinations in Output

输出中包含无效组合

  • Add missing constraints
  • Verify constraint logic is correct
  • Check if you need to use
    NOT
    or
    <>
    operators
  • 添加缺失的约束
  • 验证约束逻辑是否正确
  • 检查是否需要使用
    NOT
    <>
    运算符

Script Errors

脚本错误

  • Ensure pypict is installed:
    pip install pypict --break-system-packages
  • Check Python version (3.7+)
  • Verify model syntax is valid
  • 确保已安装pypict:
    pip install pypict --break-system-packages
  • 检查Python版本(3.7+)
  • 验证模型语法是否有效

References

参考资料

  • docs/pict_syntax.md - Complete PICT syntax reference with grammar and operators
  • docs/examples.md - Comprehensive real-world examples across different domains
  • scripts/pict_helper.py - Python utilities for model generation and output formatting
  • PICT GitHub Repository - Official PICT documentation
  • pypict Documentation - Python binding documentation
  • Online PICT Tools - Web-based PICT generator
  • docs/pict_syntax.md - 包含语法和运算符的完整PICT语法参考
  • docs/examples.md - 跨不同领域的全面真实示例
  • scripts/pict_helper.py - 用于模型生成和输出格式化的Python工具
  • PICT GitHub仓库 - 官方PICT文档
  • pypict文档 - Python绑定文档
  • 在线PICT工具 - 基于Web的PICT生成器

Examples

示例

Example 1: Simple Function Testing

示例1:简单函数测试

User Request: "Design tests for a divide function that takes two numbers and returns the result."
Analysis:
  • Parameters: dividend (number), divisor (number)
  • Values: Using equivalence partitioning and boundaries
    • Numbers: negative, zero, positive, large values
  • Constraints: Division by zero is invalid
  • Expected outputs: Result or error
PICT Model:
Dividend: -10, 0, 10, 1000
Divisor: ~0, -5, 1, 5, 100

IF [Divisor] = "0" THEN [Dividend] = "10";
Test Cases:
Test #DividendDivisorExpected Output
1100Error: Division by zero
2-101-10.0
30-50.0
410005200.0
5101000.1
用户请求: "为一个接收两个数字并返回结果的除法函数设计测试用例。"
分析:
  • 参数:被除数(数字)、除数(数字)
  • 取值:使用等价类划分和边界值
    • 数字:负数、零、正数、大数值
  • 约束:除数为零无效
  • 预期输出:结果或错误
PICT模型:
Dividend: -10, 0, 10, 1000
Divisor: ~0, -5, 1, 5, 100

IF [Divisor] = "0" THEN [Dividend] = "10";
测试用例:
测试编号被除数除数预期输出
1100错误:除零错误
2-101-10.0
30-50.0
410005200.0
5101000.1

Example 2: E-commerce Checkout

示例2:电商结账流程

User Request: "Design tests for checkout flow with payment methods, shipping options, and user types."
Analysis:
  • Payment: Credit Card, PayPal, Bank Transfer (limited by user type)
  • Shipping: Standard, Express, Overnight
  • User: Guest, Registered, Premium
  • Constraints: Guests can't use Bank Transfer, Premium users get free Express
PICT Model:
PaymentMethod: CreditCard, PayPal, BankTransfer
ShippingMethod: Standard, Express, Overnight
UserType: Guest, Registered, Premium

IF [UserType] = "Guest" THEN [PaymentMethod] <> "BankTransfer";
IF [UserType] = "Premium" AND [ShippingMethod] = "Express" THEN [PaymentMethod] IN {CreditCard, PayPal};
Output: 12-15 test cases covering all valid payment/shipping/user combinations with expected costs and outcomes.
用户请求: "为包含支付方式、配送选项和用户类型的结账流程设计测试用例。"
分析:
  • 支付方式:信用卡、PayPal、银行转账(受用户类型限制)
  • 配送方式:标准、加急、次日达
  • 用户类型:访客、注册用户、高级用户
  • 约束:访客无法使用银行转账,高级用户享受免费加急配送
PICT模型:
PaymentMethod: CreditCard, PayPal, BankTransfer
ShippingMethod: Standard, Express, Overnight
UserType: Guest, Registered, Premium

IF [UserType] = "Guest" THEN [PaymentMethod] <> "BankTransfer";
IF [UserType] = "Premium" AND [ShippingMethod] = "Express" THEN [PaymentMethod] IN {CreditCard, PayPal};
输出: 12-15个测试用例,覆盖所有有效的支付/配送/用户组合及对应的预期费用和结果。