diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 323d0652..9be5c2bb 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -78,6 +78,11 @@ "name": "hcp", "source": "./plugins/hcp", "description": "Generate HyperShift cluster creation commands via hcp CLI from natural language descriptions" + }, + { + "name": "testing", + "source": "./plugins/testing", + "description": "Comprehensive test case generation and QA automation tools" } ] } \ No newline at end of file diff --git a/PLUGINS.md b/PLUGINS.md index 13ef9a73..2926190f 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -15,6 +15,7 @@ This document lists all available Claude Code plugins and their commands in the - [Openshift](#openshift-plugin) - [Prow Job](#prow-job-plugin) - [Session](#session-plugin) +- [Testing](#testing-plugin) - [Utils](#utils-plugin) - [Yaml](#yaml-plugin) @@ -172,6 +173,15 @@ A plugin to save and resume conversation sessions across long time intervals See [plugins/session/README.md](plugins/session/README.md) for detailed documentation. +### Testing Plugin + +Comprehensive test case generation and QA automation tools + +**Commands:** +- **`/testing:generate-test-case-doc` ` [--priority high|medium|low] [--component name] [--format markdown|docx]`** - Generate comprehensive test cases for a feature with priority filtering and multiple output formats + +See [plugins/testing/README.md](plugins/testing/README.md) for detailed documentation. + ### Utils Plugin A generic utilities plugin serving as a catch-all for various helper commands and agents diff --git a/docs/data.json b/docs/data.json index d8ef00f4..93d1d4c2 100644 --- a/docs/data.json +++ b/docs/data.json @@ -603,6 +603,27 @@ } ], "has_readme": true + }, + { + "name": "testing", + "description": "Comprehensive test case generation and QA automation tools", + "version": "0.0.1", + "commands": [ + { + "name": "generate-test-case-doc", + "description": "Generate comprehensive test cases for a feature with priority filtering and multiple output formats", + "synopsis": "/testing:generate-test-case-doc [--priority high|medium|low] [--component name] [--format markdown|docx]", + "argument_hint": " [--priority high|medium|low] [--component name] [--format markdown|docx]" + } + ], + "skills": [ + { + "name": "Test Case Document Generator", + "id": "testcase-doc-generator", + "description": "Generate comprehensive test case documents with DOCX export capability" + } + ], + "has_readme": true } ] } \ No newline at end of file diff --git a/plugins/testing/.claude-plugin/plugin.json b/plugins/testing/.claude-plugin/plugin.json new file mode 100644 index 00000000..db2878c4 --- /dev/null +++ b/plugins/testing/.claude-plugin/plugin.json @@ -0,0 +1,8 @@ +{ + "name": "testing", + "description": "Comprehensive test case generation and QA automation tools", + "version": "0.0.1", + "author": { + "name": "github.com/openshift-eng" + } +} diff --git a/plugins/testing/README.md b/plugins/testing/README.md new file mode 100644 index 00000000..3b801548 --- /dev/null +++ b/plugins/testing/README.md @@ -0,0 +1,358 @@ +# Testing Plugin + +Comprehensive test case generation and QA automation tools for Claude Code. + +## Overview + +The Testing plugin provides powerful commands to automate the creation of detailed, professional test cases for any feature or functionality. It helps QA engineers, developers, and product teams quickly generate comprehensive test plans with proper categorization, priority tagging, and multiple output formats. + +## Commands + +### `/testing:generate-test-case-doc` + +Generate comprehensive test cases for a feature with priority filtering and multiple output formats. + +**Synopsis:** +``` +/testing:generate-test-case-doc [--priority high|medium|low] [--component name] [--format markdown|docx] +``` + +**Description:** + +Automatically generates detailed test cases including: +- **Functional Tests**: Core feature functionality and user workflows +- **Regression Tests**: Existing functionality validation +- **Smoke Tests**: Critical path quick checks +- **Edge Cases**: Boundary values and negative scenarios +- **Security Tests**: Authentication, authorization, and data privacy +- **Performance Tests**: Load, response time, and resource usage + +Each test case includes: +- Title and unique ID +- Priority level (High/Medium/Low) +- Component/module tags +- Test type tags (Functional, Regression, Smoke, etc.) +- Detailed test steps +- Clear expected results +- Preconditions and test data +- Notes and related test cases + +**Features:** +- 📋 **Comprehensive Coverage**: Automatically generates test cases across multiple categories +- 🎯 **Priority Filtering**: Generate only high-priority tests for critical path validation +- 🏷️ **Component Tagging**: Organize tests by module or component +- 📄 **Multiple Formats**: Output as Markdown or Microsoft Word (DOCX) +- ⚡ **Critical Test Summary**: Dedicated section for smoke and high-priority tests +- 📊 **Statistics**: Detailed breakdown by priority and test type + +**Basic Usage:** + +Generate all test cases for a feature: +```bash +/testing:generate-test-case-doc "User Authentication with OAuth2" +``` + +**Advanced Usage:** + +High-priority test cases only, with component tagging, in DOCX format: +```bash +/testing:generate-test-case-doc "Payment Processing" --priority high --component payment,security --format docx +``` + +**Options:** + +- `--priority `: Filter by priority + - Values: `high`, `medium`, `low`, `all` (default: all) + - Example: `--priority high` for critical tests only + +- `--component `: Tag with component/module name(s) + - Single: `--component auth` + - Multiple: `--component auth,api,ui` + +- `--format `: Output format + - Values: `markdown` (default), `docx` + - Markdown: Version control friendly, text-based + - DOCX: Professional formatting for stakeholders + +**Output:** + +Creates a file in the current directory: +- Markdown: `testcases-{feature-name}.md` +- DOCX: `testcases-{feature-name}.docx` + +The document includes: +1. **Overview**: Feature description and scope +2. **Test Environment Requirements**: Prerequisites and dependencies +3. **Test Cases**: Organized by type (Functional, Regression, Smoke, etc.) +4. **Critical Test Cases Summary**: Quick validation checklist +5. **Test Execution Notes**: Execution order and reporting guidelines +6. **Appendix**: Test case statistics + +**Examples:** + +1. **Basic feature test cases**: + ```bash + /testing:generate-test-case-doc "Shopping Cart Updates" + ``` + +2. **High-priority smoke tests**: + ```bash + /testing:generate-test-case-doc "API Gateway" --priority high + ``` + +3. **Component-specific tests**: + ```bash + /testing:generate-test-case-doc "User Profile Management" --component profile,api + ``` + +4. **Professional DOCX for stakeholders**: + ```bash + /testing:generate-test-case-doc "Payment Integration" --format docx + ``` + +5. **Critical security tests**: + ```bash + /testing:generate-test-case-doc "OAuth2 Implementation" --priority high --component auth,security --format docx + ``` + +## Installation + +### From Marketplace + +```bash +# Add the marketplace +/plugin marketplace add openshift-eng/ai-helpers + +# Install the testing plugin +/plugin install testing@ai-helpers +``` + +### Manual Installation + +```bash +# Clone the repository +git clone https://github.com/openshift-eng/ai-helpers.git + +# Link to Claude Code plugins directory +ln -s $(pwd)/ai-helpers/plugins/testing ~/.claude/plugins/testing +``` + +## Prerequisites + +### For Markdown Output (Default) +- No additional dependencies required +- Works out of the box + +### For DOCX Output +- Python 3.7+ +- `python-docx` library + +Install dependencies: +```bash +pip install python-docx +``` + +Or using requirements file: +```bash +# Create requirements.txt +echo "python-docx>=0.8.11" > requirements.txt + +# Install +pip install -r requirements.txt +``` + +## Use Cases + +### For QA Engineers +- **New Feature Testing**: Quickly generate comprehensive test plans for new features +- **Regression Suites**: Build regression test suites for major releases +- **Critical Path Testing**: Generate smoke tests for quick validation + +### For Developers +- **Feature Documentation**: Document testing requirements alongside code +- **Test Coverage**: Ensure comprehensive test coverage during development +- **PR Validation**: Create test cases for pull request validation + +### For Product Teams +- **Acceptance Criteria**: Generate test cases from feature requirements +- **Stakeholder Review**: Create professional DOCX documents for review +- **Release Planning**: Build test plans for release validation + +### For CI/CD Integration +- **Automated Documentation**: Generate test case documentation as part of CI +- **Version Control**: Maintain test cases in markdown format alongside code +- **Test Management**: Import generated test cases into test management tools + +## Output Structure + +### Markdown Format +```markdown +# Test Cases: Feature Name + +**Generated**: 2025-01-15 10:30:00 +**Feature**: Feature Name +**Component**: component-name +**Total Test Cases**: 25 + +--- + +## 1. Overview +Feature description and scope... + +## 2. Test Environment Requirements +Prerequisites and dependencies... + +## 3. Test Cases + +### 3.1 Functional Tests +TC-001: Test Case Title +... + +### 3.2 Regression Tests +TC-010: Test Case Title +... + +### 3.3 Smoke Tests +TC-020: Test Case Title +... + +## 4. Critical Test Cases Summary +Quick validation checklist... + +## 5. Test Execution Notes +Execution order and reporting... + +## Appendix +Test case statistics... +``` + +### DOCX Format +Professional Word document with: +- Styled headings and formatting +- Tables for test case summaries +- Proper spacing and structure +- Blue color scheme for headings +- Easy sharing with stakeholders + +## Tips and Best Practices + +### Priority Levels +- **High**: Critical functionality, blocking issues, smoke tests + - Use for: Core features, security, data integrity + - Execute first in testing cycles + +- **Medium**: Important features, common scenarios + - Use for: Standard workflows, integration testing + - Execute after high-priority tests + +- **Low**: Edge cases, optional features + - Use for: Nice-to-have features, rare scenarios + - Execute time permitting + +### Component Organization +- Use consistent component names across projects +- Examples: `auth`, `api`, `ui`, `database`, `payment`, `security` +- Multiple components for cross-functional features +- Helps organize and filter test cases + +### Format Selection +- **Use Markdown when**: + - Storing test cases in version control + - Collaborating with developers + - Automating test case updates + - Integrating with CI/CD + +- **Use DOCX when**: + - Sharing with non-technical stakeholders + - Creating formal test plans + - Presenting to management + - Archiving test documentation + +### Customization +Generated test cases should be reviewed and enhanced: +- Add specific test data values +- Update preconditions for your environment +- Add links to related documentation +- Include screenshots or diagrams +- Update expected results with exact values + +### Integration with Test Management Tools +Generated test cases can be imported into: +- TestRail +- Zephyr +- qTest +- Azure Test Plans +- JIRA Test Management + +Export format: Markdown or DOCX → Convert using tool-specific importers + +## Troubleshooting + +### DOCX Generation Fails + +**Error**: `ImportError: No module named 'docx'` + +**Solution**: +```bash +pip install python-docx +``` + +### Invalid Priority Value + +**Error**: `Invalid priority filter` + +**Solution**: Use one of: `high`, `medium`, `low`, `all` + +### File Permission Denied + +**Error**: `Permission denied: testcases-*.md` + +**Solution**: +- Check write permissions in current directory +- Try saving to a different directory +- Verify disk space availability + +### Empty Test Cases Generated + +**Issue**: Very few or generic test cases created + +**Solution**: +- Provide more context about the feature +- Include feature description or requirements +- Reference existing documentation or specs +- Manually add feature details to the prompt + +## Contributing + +Contributions welcome! To add new features or improve test case generation: + +1. Fork the repository +2. Create a feature branch +3. Update the command or add new commands +4. Test thoroughly +5. Submit a pull request + +## Support + +- **Issues**: https://github.com/openshift-eng/ai-helpers/issues +- **Documentation**: https://github.com/openshift-eng/ai-helpers +- **Discussions**: https://github.com/openshift-eng/ai-helpers/discussions + +## Related Commands + +- `/utils:generate-test-plan` - Generate test plans from GitHub PRs +- `/jira:generate-test-plan` - Generate test plans from JIRA issues + +## License + +See repository LICENSE file for details. + +## Version History + +### v0.0.1 (2025-01-15) +- Initial release +- Feature-based test case generation +- Priority filtering +- Component tagging +- Markdown and DOCX output formats +- Critical test case summary diff --git a/plugins/testing/commands/generate-test-case-doc.md b/plugins/testing/commands/generate-test-case-doc.md new file mode 100644 index 00000000..423f5fa3 --- /dev/null +++ b/plugins/testing/commands/generate-test-case-doc.md @@ -0,0 +1,738 @@ +--- +description: Generate comprehensive test cases for a feature with priority filtering and multiple output formats +argument-hint: [--priority high|medium|low] [--component name] [--format markdown|docx] +--- + +## Name +testing:generate-test-case-doc + +## Synopsis +``` +/testing:generate-test-case-doc [--priority high|medium|low] [--component name] [--format markdown|docx] +``` + +## Description + +The `testing:generate-test-case-doc` command generates comprehensive, detailed test cases for any new feature or functionality. It analyzes the feature requirements, generates multiple test scenarios covering different aspects (functional, regression, smoke, edge cases), and outputs a well-structured document that can be used by QA teams. + +This command automates the creation of: +- Detailed test cases with clear steps and expected results +- Priority-based categorization (High/Medium/Low) +- Test type tagging (Regression, Smoke, Functional, Integration, etc.) +- Critical test case summary for quick validation +- Support for multiple output formats (Markdown, DOCX) + +The command is designed for: +- QA engineers creating test plans for new features +- Developers documenting testing requirements +- Product teams validating feature completeness +- CI/CD integration for automated test documentation + +## Implementation + +### Process Flow + +1. **Parse Arguments and Flags**: + - **$1** (feature_name): Required - The name or description of the feature to test + - Example: "User Authentication with OAuth2" + - **--priority**: Optional filter to generate only test cases of specific priority + - Values: `high`, `medium`, `low`, `all` (default: all) + - Example: `--priority high` generates only high-priority test cases + - **--component**: Optional component/module tag for organizing test cases + - Example: `--component auth` tags all tests with the auth component + - Multiple components: `--component auth,api,ui` + - **--format**: Output format + - Values: `markdown` (default), `docx` + - Example: `--format docx` generates a Word document + + Parse these arguments using bash parameter parsing: + ```bash + FEATURE_NAME="$1" + PRIORITY_FILTER="all" + COMPONENT="" + FORMAT="markdown" + + shift # Remove feature_name from arguments + + while [[ $# -gt 0 ]]; do + case "$1" in + --priority) + PRIORITY_FILTER="$2" + shift 2 + ;; + --component) + COMPONENT="$2" + shift 2 + ;; + --format) + FORMAT="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac + done + ``` + +2. **Validate Inputs**: + - Check if feature_name is provided: + ```bash + if [ -z "$FEATURE_NAME" ]; then + echo "Error: Feature name is required" + echo "Usage: /testing:generate-test-case-doc [options]" + exit 1 + fi + ``` + - Validate priority filter (if provided): + - Must be one of: `high`, `medium`, `low`, `all` + - If invalid, display error and exit + - Validate format: + - Must be one of: `markdown`, `docx` + - If invalid, default to markdown with warning + +3. **Analyze Feature Context and Codebase** (CRITICAL - DO NOT SKIP): + + **IMPORTANT**: This step is essential for generating relevant, accurate test cases. Spend time gathering context from the actual codebase. + + **A. Search for Feature Documentation** + + Display message: "🔍 Analyzing codebase for '{feature_name}'..." + + - Find documentation files mentioning the feature: + ```bash + # Search all markdown files + grep -r -i "{feature_name}" --include="*.md" --include="*.txt" --include="*.rst" + ``` + + - Look for key documentation files: + - README.md (installation, setup, usage) + - CONTRIBUTING.md (development setup) + - docs/ directory + - Design documents, RFCs, proposals + - CHANGELOG.md (feature additions) + + - Extract from documentation: + - Installation/setup steps + - Prerequisites (tools, versions, dependencies) + - Configuration requirements + - Usage examples + - Known limitations + + **B. Find Existing Test Files** (Learn from existing patterns) + + Display message: "📋 Looking for existing test files..." + + - Search for test files in common locations: + ```bash + # Find test files + find . -type f \( -name "*test*.go" -o -name "*test*.py" -o -name "*_test.js" -o -name "test_*.py" -o -name "*_spec.rb" \) + + # Search test files for feature mentions + grep -r -i "{feature_name}" test/ tests/ spec/ --include="*test*" --include="*spec*" + ``` + + - Look for test files containing the feature name + - Read relevant test files to understand: + - Test structure and patterns used in this project + - How tests are organized (by feature, by component, etc.) + - Setup/teardown procedures + - Assertion styles + - Mock/stub patterns + - Test data examples + + - **IMPORTANT**: If existing test files are found for this feature: + - Read them completely + - Learn the test case format used + - Identify what scenarios are already tested + - Use similar naming conventions + - Follow the same structure + + **C. Search for Implementation Code** + + Display message: "💻 Searching implementation files..." + + - Find source code related to the feature: + ```bash + # Search source code + grep -r -i "{feature_name}" --include="*.go" --include="*.py" --include="*.js" --include="*.java" --include="*.rb" --include="*.ts" | head -50 + ``` + + - Identify key implementation files + - Understand: + - Main components involved + - APIs or interfaces + - Configuration options + - Dependencies on external systems + - Entry points (CLI commands, API endpoints, etc.) + + **D. Identify Setup and Configuration Requirements** + + Display message: "⚙️ Identifying setup requirements..." + + - Search for configuration files: + ```bash + # Find config files + find . -type f \( -name "*.yaml" -o -name "*.yml" -o -name "*.json" -o -name "*.conf" -o -name "*.toml" -o -name "*.ini" \) | grep -v vendor | grep -v node_modules | head -20 + ``` + + - Look for: + - Deployment manifests (Kubernetes, Docker Compose) + - Configuration examples + - Environment variables + - Command-line flags + - Default settings + + - Check for installation/setup scripts: + - Makefile targets + - install.sh, setup.sh + - Package managers (package.json, requirements.txt, go.mod) + + **E. Analyze Integration Points and Dependencies** + + Display message: "🔗 Analyzing integrations..." + + - Identify external dependencies: + - Check README for prerequisites + - Look for mentions of: + - Container runtimes (Docker, containerd, CRI-O) + - Kubernetes/OpenShift + - Databases + - Message queues + - External APIs or services + + - Understand platform-specific requirements: + - Operating system requirements + - Kernel features needed + - Network requirements + - Storage requirements + + **F. Extract Commands and Tools Used** + + - Find command-line usage: + - Search for CLI commands in docs + - Look for kubectl, oc, docker commands + - Identify custom tools or scripts + + - Extract from code/docs: + - Actual commands users run + - API endpoints + - Configuration values + - File paths + + **G. Summarize Context Gathered** + + Display message: "✓ Context analysis complete" + + Create a context summary with: + - Repository type (Go project, Python project, K8s operator, etc.) + - Feature location (which files implement it) + - Existing test file(s) found (if any) + - Setup/installation steps identified + - Key tools/commands involved + - Platform-specific requirements + - Integration dependencies + + **IMPORTANT Decision Point**: + - If existing test files found for this feature → Use them as primary reference + - If similar test files found → Learn patterns and adapt + - If no test files found → Generate from documentation and code analysis + + This context will be used to generate accurate, repository-specific test cases. + + **IMPORTANT**: Do NOT ask for user confirmation after gathering context. Proceed directly to Step 4 (Generate Comprehensive Test Cases) using the gathered context. + +4. **Generate Comprehensive Test Cases**: + + **IMPORTANT**: Use the context gathered in Step 3 to create relevant, repository-specific test cases. + + **Context-Driven Test Generation**: + + - **If existing test files were found**: + - Use their structure and format as the primary template + - Follow their naming conventions (e.g., TC-001, Test-01, etc.) + - Match their level of detail and specificity + - Learn from scenarios already tested + - Extend with additional scenarios not covered + + - **Use discovered setup/installation steps**: + - In preconditions, reference actual installation steps from README + - Include actual configuration files found (yaml, json, conf) + - Reference specific tools/versions from prerequisites + + - **Use actual commands and tools found**: + - In test steps, use real CLI commands discovered (kubectl, oc, docker, etc.) + - Reference actual API endpoints from code + - Use actual configuration values from examples + - Include real file paths from the repository + + - **Reference platform-specific requirements**: + - Include platform requirements discovered (K8s version, CRI-O config, etc.) + - Reference container runtime specifics + - Mention OS or kernel requirements found + + Create test cases covering these categories: + + **A. Functional Test Cases** (Core feature functionality): + - Happy path scenarios (using actual commands from docs) + - Alternative flows (based on code analysis) + - User workflows (from README usage examples) + - Data validation scenarios (based on implementation details) + + **B. Regression Test Cases** (Ensure existing functionality works): + - Related feature interactions (from integration points found) + - Backward compatibility checks (if version info found) + - Integration with existing modules (from dependency analysis) + + **C. Smoke Test Cases** (Critical path validation): + - Core functionality quick checks (based on critical paths in code) + - Basic feature availability (from installation validation) + - Critical user journeys (from documentation examples) + + **D. Edge Cases and Negative Test Cases**: + - Boundary value testing (based on code constraints) + - Invalid input handling (from error handling in code) + - Error message validation (using actual error messages from code) + - Timeout and failure scenarios (from configuration limits) + + **E. Security Test Cases** (if applicable): + - Authentication/Authorization checks (if auth found in code) + - Data privacy validations (based on security requirements) + - Input sanitization tests (from injection points in code) + + **F. Performance Test Cases** (if applicable): + - Load testing scenarios (based on resource limits in config) + - Response time validations (from SLO/SLA docs if found) + - Resource usage checks (from deployment manifests) + + For each test case, generate: + ``` + TC-{NUMBER}: {Test Case Title} + + **Priority**: High | Medium | Low + **Component**: {component_name} + **Tags**: [Functional, Regression, Smoke, etc.] + **Preconditions**: + - List of setup requirements + + **Test Steps**: + 1. Step one with clear action + 2. Step two with clear action + 3. ... + + **Expected Result**: + - Clear, measurable expected outcome + - Verification criteria + + **Test Data** (if applicable): + - Input data specifications + - Test user accounts + - Configuration values + + **Notes**: + - Additional considerations + - Related test cases + ``` + +5. **Apply Filters**: + - If `--priority` filter is specified: + - Include only test cases matching the specified priority + - Maintain all other metadata + - If `--component` is specified: + - Tag all test cases with the specified component + - Can be comma-separated for multiple components + +6. **Create Document Structure**: + + Generate document with the following sections: + + ```markdown + # Test Cases: {Feature Name} + + **Generated**: {Current Date and Time} + **Feature**: {Feature Name} + **Component**: {Component Name(s)} + **Priority Filter**: {Priority Filter Applied} + **Total Test Cases**: {Count} + + --- + + ## Table of Contents + 1. Overview + 2. Setup and Installation + 3. Test Environment Requirements + 4. Test Cases + - 4.1 Functional Tests + - 4.2 Regression Tests + - 4.3 Smoke Tests + - 4.4 Edge Cases + - 4.5 Security Tests (if applicable) + - 4.6 Performance Tests (if applicable) + 5. Critical Test Cases Summary + 6. Test Execution Notes + + --- + + ## 1. Overview + + **Feature Description**: {Brief description of the feature based on docs/code analysis} + + **Scope**: {What is being tested - derived from feature context} + + **Out of Scope**: {What is not covered} + + **Project**: {Repository name if identifiable} + + --- + + ## 2. Setup and Installation + + **IMPORTANT**: Populate this section with actual setup steps discovered in Step 3. + + **Installation Steps**: + {Extract from README.md, INSTALL.md, or installation scripts found} + - Include actual commands with full paths + - Reference specific versions if found + - Include prerequisite installations + + **Configuration**: + {Extract from configuration files and setup documentation} + - Include actual configuration file snippets + - Reference environment variables needed + - Include platform-specific configuration (e.g., CRI-O setup) + + **Verification**: + {Include verification steps from documentation} + - Commands to verify installation success + - Expected output examples + - Health check procedures + + --- + + ## 3. Test Environment Requirements + + **Prerequisites**: + {Populate with actual requirements discovered in Step 3} + - Specific tools and versions (from README/package files) + - Platform requirements (OS, kernel version from docs) + - Access requirements (cluster admin, specific RBAC) + - External dependencies (databases, message queues from code analysis) + + **Test Data**: + {Reference actual test data from existing test files or examples} + - Test configuration files (from test/ directory) + - Sample input data (from examples/ or test fixtures) + - Test accounts/credentials needed + + **Dependencies**: + {List actual dependencies discovered} + - Runtime dependencies (Kubernetes, OpenShift from manifests) + - External services (from integration points in code) + - Network requirements (from deployment configs) + + --- + + ## 4. Test Cases + + ### 4.1 Functional Tests + + {Generated functional test cases - use context from Step 3} + + ### 4.2 Regression Tests + + {Generated regression test cases - use context from Step 3} + + ### 4.3 Smoke Tests + + {Generated smoke test cases - use context from Step 3} + + ### 4.4 Edge Cases + + {Generated edge case test cases - use context from Step 3} + + ### 4.5 Security Tests + + {Generated security test cases if applicable - use context from Step 3} + + ### 4.6 Performance Tests + + {Generated performance test cases if applicable - use context from Step 3} + + --- + + ## 5. Critical Test Cases Summary + + This section lists all **High Priority** and **Smoke** test cases for quick validation: + + | TC ID | Title | Priority | Type | Expected Result | + |-------|-------|----------|------|----------------| + | TC-001 | ... | High | Smoke | ... | + | TC-003 | ... | High | Functional | ... | + | ... | ... | ... | ... | ... | + + **Quick Validation Steps**: + 1. Execute all Smoke tests (TC-XXX, TC-YYY) + 2. Execute all High Priority tests + 3. Verify critical user journeys + + --- + + ## 6. Test Execution Notes + + **Execution Order**: + - Recommended order for test execution (based on test dependencies discovered) + + **Known Issues**: + - Any known limitations or issues discovered in Step 3 analysis + - Reference to existing issues in issue tracker if found + + **Reporting**: + - How to report test results + - Defect tracking information (reference actual project tools if found) + + --- + + ## Appendix + + **Test Case Statistics**: + - Total: {total_count} + - High Priority: {high_count} + - Medium Priority: {medium_count} + - Low Priority: {low_count} + - Smoke Tests: {smoke_count} + - Regression Tests: {regression_count} + - Functional Tests: {functional_count} + + **Context Analysis**: + - Existing test files found: {count or "None"} + - Documentation files analyzed: {count} + - Implementation files analyzed: {count} + - Setup steps extracted: {Yes/No} + + **Generated by**: Claude Code `/testing:generate-test-case-doc` command + **Timestamp**: {ISO 8601 timestamp} + **Working Directory**: {pwd output - the repository/directory being analyzed} + **Command**: `/testing:generate-test-case-doc "{feature_name}" {flags if any}` + ``` + +7. **Generate Output File**: + + **A. For Markdown format (default)**: + - Filename: `testcases-{sanitized_feature_name}.md` + - Sanitize feature name: lowercase, replace spaces with hyphens + - Example: "User Authentication" → `testcases-user-authentication.md` + - Save to current working directory + - Use Write tool to create the file + + **B. For DOCX format**: + - Filename: `testcases-{sanitized_feature_name}.docx` + - Use the helper script: `python3 plugins/testing/skills/testcase-doc-generator/generate_docx.py` + - Script usage: + ```bash + python3 plugins/testing/skills/testcase-doc-generator/generate_docx.py \ + --input testcases-{sanitized_feature_name}.md \ + --output testcases-{sanitized_feature_name}.docx \ + --title "Test Cases: {Feature Name}" + ``` + - The script converts markdown to properly formatted DOCX with: + - Styled headings (Heading 1, 2, 3) + - Tables for test case summaries + - Proper spacing and formatting + - Table of contents (if supported) + +8. **Display Results to User**: + ``` + ✓ Test cases generated successfully! + + Feature: {Feature Name} + Total Test Cases: {count} + Priority Filter: {filter if applied} + Component: {component if specified} + + Breakdown: + - High Priority: {count} + - Medium Priority: {count} + - Low Priority: {count} + + Test Types: + - Functional: {count} + - Regression: {count} + - Smoke: {count} + - Edge Cases: {count} + - Security: {count} + - Performance: {count} + + Output saved to: {file_path} + Format: {markdown/docx} + + Critical test cases ({count}) are highlighted in Section 4 for quick validation. + + Next steps: + - Review the generated test cases + - Customize test data and preconditions + - Execute smoke tests first + - Report any issues found + ``` + +9. **Post-Generation Options**: + Ask the user if they would like to: + - Generate additional test cases for specific scenarios + - Export to a different format + - Create a filtered version (e.g., only smoke tests) + - Add custom test cases to the document + +## Return Value + +- **Success**: + - File path of generated test cases document + - Summary statistics of test cases created + - Breakdown by priority and type + +- **Error**: + - Clear error message if feature name missing + - Validation errors for invalid flags + - File write errors with troubleshooting steps + +- **Format**: Structured summary with: + - Generated file location + - Test case counts and categories + - Critical test case highlights + - Next steps for the user + +## Examples + +### Example 1: Basic usage (all test cases, markdown) +``` +/testing:generate-test-case-doc "User Authentication with OAuth2" +``` + +**Output**: +- Generates `testcases-user-authentication-with-oauth2.md` +- Includes all priority levels (High, Medium, Low) +- All test types (Functional, Regression, Smoke, Edge Cases, Security) +- Critical test summary section + +### Example 2: High priority test cases only +``` +/testing:generate-test-case-doc "User Authentication with OAuth2" --priority high +``` + +**Output**: +- Generates only High priority test cases +- Useful for critical path testing +- Faster test execution planning + +### Example 3: With component tagging +``` +/testing:generate-test-case-doc "User Authentication with OAuth2" --component auth +``` + +**Output**: +- All test cases tagged with `Component: auth` +- Helps organize test cases by module + +### Example 4: Multiple components +``` +/testing:generate-test-case-doc "API Gateway Rate Limiting" --component api,gateway,security +``` + +**Output**: +- Test cases tagged with multiple components +- Useful for cross-functional features + +### Example 5: DOCX format for sharing +``` +/testing:generate-test-case-doc "User Authentication with OAuth2" --format docx +``` + +**Output**: +- Generates `testcases-user-authentication-with-oauth2.docx` +- Professional Word document with proper formatting +- Easy to share with non-technical stakeholders + +### Example 6: Filtered high-priority DOCX for specific component +``` +/testing:generate-test-case-doc "Payment Processing" --priority high --component payment,security --format docx +``` + +**Output**: +- High priority test cases only +- Tagged with payment and security components +- DOCX format for stakeholder review +- Focused on critical payment security scenarios + +### Example 7: Medium priority test cases for regression suite +``` +/testing:generate-test-case-doc "Shopping Cart Updates" --priority medium --component cart +``` + +**Output**: +- Medium priority test cases +- Suitable for extended regression testing +- Component-specific test organization + +## Arguments + +- **$1** (feature_name): The name or description of the feature to generate test cases for (required) + - Example: "User Authentication with OAuth2" + - Can be a brief description or full feature name + - Spaces and special characters are supported + +- **--priority** (filter): Filter test cases by priority level (optional) + - Values: `high`, `medium`, `low`, `all` + - Default: `all` (generates all priority levels) + - Example: `--priority high` generates only critical test cases + +- **--component** (name): Tag test cases with component/module name(s) (optional) + - Can be single component: `--component auth` + - Can be multiple components: `--component auth,api,ui` + - Helps organize test cases by system module + - Default: No component tag + +- **--format** (type): Output file format (optional) + - Values: `markdown`, `docx` + - Default: `markdown` + - `markdown`: Creates `.md` file (text-based, version control friendly) + - `docx`: Creates Microsoft Word document (professional formatting, easy sharing) + +## Notes + +- **Test Case Quality**: Generated test cases are comprehensive but should be reviewed and customized based on specific requirements +- **Component Tagging**: Use consistent component names across projects for better organization +- **Priority Guidance**: + - **High**: Critical functionality, blocking issues, smoke tests + - **Medium**: Important features, common user scenarios, regression coverage + - **Low**: Edge cases, optional features, nice-to-have validations +- **DOCX Generation**: Requires Python with `python-docx` library. The helper script will notify if dependencies are missing +- **File Location**: Test cases are saved in the current working directory. Use absolute paths if needed +- **Version Control**: Markdown format is recommended for version-controlled test cases +- **Customization**: Review and enhance generated test cases with: + - Specific test data values + - Environment-specific configurations + - Team-specific testing conventions +- **Integration**: Generated test cases can be imported into test management tools (TestRail, Zephyr, etc.) + +## Troubleshooting + +- **Missing dependencies for DOCX**: + ```bash + pip install python-docx + ``` + +- **Invalid priority filter**: Ensure value is one of: `high`, `medium`, `low`, `all` + +- **File write errors**: + - Check write permissions in current directory + - Ensure disk space is available + - Verify filename doesn't contain invalid characters + +- **Empty test cases**: + - Provide more context about the feature + - Check if feature name is too vague + - Manually add feature description in the prompt + +## See Also + +- `/utils:generate-test-plan` - Generate test plans from GitHub PRs +- `/jira:generate-test-plan` - Generate test plans from JIRA issues diff --git a/plugins/testing/skills/testcase-doc-generator/SKILL.md b/plugins/testing/skills/testcase-doc-generator/SKILL.md new file mode 100644 index 00000000..d05f36c7 --- /dev/null +++ b/plugins/testing/skills/testcase-doc-generator/SKILL.md @@ -0,0 +1,280 @@ +--- +name: Test Case Document Generator +description: Generate comprehensive test case documents with DOCX export capability +--- + +# Test Case Document Generator Skill + +This skill provides the implementation details for generating comprehensive test case documents from feature descriptions and exporting them to multiple formats. + +## When to Use This Skill + +Use this skill when the `/testing:generate-test-case-doc` command needs to: +- Generate detailed test cases for a new feature +- Export test cases to DOCX format +- Apply priority or component filters +- Create professional test documentation + +## Prerequisites + +### For Markdown Output +- No additional dependencies required + +### For DOCX Output +- Python 3.7 or higher +- `python-docx` library + +Check Python version: +```bash +python3 --version +``` + +Check if python-docx is installed: +```bash +python3 -c "import docx; print('python-docx installed')" 2>/dev/null || echo "python-docx not installed" +``` + +Install python-docx if needed: +```bash +pip install python-docx +``` + +## Implementation Details + +### DOCX Generation Script + +**Location**: `plugins/testing/skills/testcase-doc-generator/generate_docx.py` + +**Purpose**: Converts markdown-formatted test cases into a professionally formatted Microsoft Word document. + +**Usage**: +```bash +python3 plugins/testing/skills/testcase-doc-generator/generate_docx.py \ + --input testcases-{feature-name}.md \ + --output testcases-{feature-name}.docx \ + --title "Test Cases: {Feature Name}" +``` + +**Parameters**: +- `--input` / `-i`: Path to input markdown file (required) +- `--output` / `-o`: Path to output DOCX file (required) +- `--title` / `-t`: Document title (required) + +**What the Script Does**: + +1. **Reads Markdown File**: + - Parses markdown content line by line + - Handles frontmatter (YAML between `---`) + - Processes markdown elements + +2. **Converts to DOCX**: + - Headings (`#`, `##`, `###`) → Word Heading styles + - Bold text (`**text**`) → Bold formatting + - Code blocks (` ``` `) → Courier New font + - Tables (`|...|`) → Formatted Word tables + - Lists (`-`, `*`, `1.`) → Bullet and numbered lists + - Horizontal rules (`---`) → Separator lines + +3. **Applies Styling**: + - Title: Calibri 24pt, Bold, Dark Blue + - Headings: Calibri, Dark Blue + - Normal text: Calibri 11pt + - Code: Courier New 9pt + - Tables: Light Grid Accent 1 style with blue header + +4. **Creates Output**: + - Saves to specified output path + - Reports document statistics (pages, sections) + +### Error Handling + +**Missing python-docx**: +``` +Error: python-docx library not found. +Install it with: pip install python-docx +``` + +**Solution**: Install the library +```bash +pip install python-docx +``` + +**Input file not found**: +``` +Error: Input file not found: {path} +``` + +**Solution**: Verify the markdown file was created successfully before calling the DOCX generator + +**Conversion errors**: +``` +Error converting markdown to DOCX: {error message} +``` + +**Solution**: Check markdown formatting, ensure valid UTF-8 encoding + +## Output Format + +### Markdown Document Structure + +```markdown +# Test Cases: {Feature Name} + +**Generated**: {timestamp} +**Feature**: {feature_name} +**Component**: {component_names} +**Priority Filter**: {priority_filter} +**Total Test Cases**: {count} + +--- + +## Table of Contents +... + +## 1. Overview +Feature description and scope + +## 2. Test Environment Requirements +Prerequisites, test data, dependencies + +## 3. Test Cases + +### 3.1 Functional Tests +TC-001: Test case title +**Priority**: High +**Component**: component-name +**Tags**: [Functional, Regression] +... + +### 3.2 Regression Tests +... + +### 3.3 Smoke Tests +... + +### 3.4 Edge Cases +... + +### 3.5 Security Tests +... + +### 3.6 Performance Tests +... + +## 4. Critical Test Cases Summary +Quick validation table + +## 5. Test Execution Notes +Execution order, known issues, reporting + +## Appendix +Test case statistics +``` + +### DOCX Document Features + +- Professional formatting with styled headings +- Tables with blue headers +- Proper spacing and indentation +- Monospace font for code blocks +- Approximately 1 page per 40 paragraphs +- Section counting for navigation + +## Examples + +### Example 1: Basic DOCX Generation + +**Input Markdown**: `testcases-user-auth.md` + +**Command**: +```bash +python3 plugins/testing/skills/testcase-doc-generator/generate_docx.py \ + --input testcases-user-auth.md \ + --output testcases-user-auth.docx \ + --title "Test Cases: User Authentication" +``` + +**Output**: +``` +✓ DOCX document created: testcases-user-auth.docx + Pages: Approximately 5 + Sections: 23 +``` + +### Example 2: With Complex Feature Name + +**Input**: Feature with special characters + +**Command**: +```bash +python3 plugins/testing/skills/testcase-doc-generator/generate_docx.py \ + --input "testcases-payment-processing-v2.md" \ + --output "testcases-payment-processing-v2.docx" \ + --title "Test Cases: Payment Processing v2.0" +``` + +## Tips + +- **Always create markdown first**: Generate markdown output, then convert to DOCX +- **Validate markdown**: Ensure markdown is well-formed before conversion +- **Use descriptive titles**: DOCX title appears in the document header +- **Check dependencies**: Verify python-docx is installed before attempting conversion +- **Handle spaces**: Quote file paths with spaces +- **Verify output**: Check the generated DOCX opens correctly in Word or LibreOffice + +## Integration with Main Command + +The `/testing:generate-test-case-doc` command uses this skill in the following flow: + +1. **Parse arguments**: Extract feature name, priority, component, format +2. **Generate test cases**: Create comprehensive test case content +3. **Write markdown**: Always create markdown file first +4. **If DOCX requested**: + - Check python-docx availability + - Call `generate_docx.py` script + - Verify DOCX creation + - Report both markdown and DOCX file locations + +## Troubleshooting + +### Issue: DOCX not generated + +**Check**: +```bash +# Verify python-docx +python3 -c "import docx" + +# Check file permissions +ls -la testcases-*.md + +# Manually test script +python3 plugins/testing/skills/testcase-doc-generator/generate_docx.py --help +``` + +### Issue: Formatting issues in DOCX + +**Common causes**: +- Malformed markdown tables +- Unclosed code blocks +- Invalid UTF-8 characters + +**Solution**: Review and fix markdown formatting + +### Issue: Script not found + +**Check working directory**: +```bash +pwd +ls -la plugins/testing/skills/testcase-doc-generator/generate_docx.py +``` + +**Solution**: Use full path or ensure running from repository/directory root + +## Version History + +### v0.0.1 +- Initial implementation +- Markdown to DOCX conversion +- Basic styling and formatting +- Table support +- Code block formatting diff --git a/plugins/testing/skills/testcase-doc-generator/generate_docx.py b/plugins/testing/skills/testcase-doc-generator/generate_docx.py new file mode 100755 index 00000000..ff1c9b05 --- /dev/null +++ b/plugins/testing/skills/testcase-doc-generator/generate_docx.py @@ -0,0 +1,285 @@ +#!/usr/bin/env python3 +""" +Generate DOCX (Word) document from Markdown test cases. + +This script converts markdown-formatted test cases into a professionally +formatted Microsoft Word document (.docx) with proper styling, tables, +and structure. + +Usage: + python3 generate_docx.py --input --output --title + +Example: + python3 generate_docx.py \ + --input testcases-user-auth.md \ + --output testcases-user-auth.docx \ + --title "Test Cases: User Authentication" + +Requirements: + - python-docx: Install with `pip install python-docx` +""" + +import sys +import argparse +import re +from pathlib import Path + +try: + from docx import Document + from docx.shared import Pt, Inches, RGBColor + from docx.enum.text import WD_ALIGN_PARAGRAPH + from docx.enum.style import WD_STYLE_TYPE +except ImportError: + print("Error: python-docx library not found.", file=sys.stderr) + print("Install it with: pip install python-docx", file=sys.stderr) + sys.exit(1) + + +def parse_arguments(): + """Parse command-line arguments.""" + parser = argparse.ArgumentParser( + description="Convert Markdown test cases to DOCX format" + ) + parser.add_argument( + "--input", + "-i", + required=True, + help="Input markdown file path" + ) + parser.add_argument( + "--output", + "-o", + required=True, + help="Output DOCX file path" + ) + parser.add_argument( + "--title", + "-t", + required=True, + help="Document title" + ) + return parser.parse_args() + + +def setup_document_styles(doc): + """Configure document styles for headings and paragraphs.""" + # Title style + title_style = doc.styles['Title'] + title_font = title_style.font + title_font.name = 'Calibri' + title_font.size = Pt(24) + title_font.bold = True + title_font.color.rgb = RGBColor(0, 51, 102) # Dark blue + + # Heading styles + for i in range(1, 4): + heading_style = doc.styles[f'Heading {i}'] + heading_font = heading_style.font + heading_font.name = 'Calibri' + heading_font.color.rgb = RGBColor(0, 51, 102) # Dark blue + + # Normal text + normal_style = doc.styles['Normal'] + normal_font = normal_style.font + normal_font.name = 'Calibri' + normal_font.size = Pt(11) + + +def parse_markdown_table(lines): + """Parse markdown table and return rows.""" + rows = [] + for line in lines: + line = line.strip() + if line.startswith('|') and line.endswith('|'): + # Remove leading/trailing pipes and split + cells = [cell.strip() for cell in line[1:-1].split('|')] + # Skip separator rows (containing only dashes and pipes) + if not all(set(cell.strip()) <= {'-', ' ', ':'} for cell in cells): + rows.append(cells) + return rows + + +def add_table_to_doc(doc, rows): + """Add a table to the document.""" + if not rows or len(rows) < 2: + return + + # Create table + table = doc.add_table(rows=len(rows), cols=len(rows[0])) + table.style = 'Light Grid Accent 1' + + # Populate table + for i, row in enumerate(rows): + for j, cell_text in enumerate(row): + cell = table.rows[i].cells[j] + cell.text = cell_text + + # Make header row bold + if i == 0: + for paragraph in cell.paragraphs: + for run in paragraph.runs: + run.font.bold = True + run.font.color.rgb = RGBColor(255, 255, 255) + # Header background color + cell._element.get_or_add_tcPr().append( + cell._element._new_tag('w:shd') + ) + cell._element.tcPr.shd.set( + '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', + '0070C0' # Blue + ) + + +def convert_markdown_to_docx(input_file, output_file, title): + """Convert markdown file to DOCX with proper formatting.""" + # Read markdown content + with open(input_file, 'r', encoding='utf-8') as f: + lines = f.readlines() + + # Create document + doc = Document() + setup_document_styles(doc) + + # Add title + title_para = doc.add_heading(title, level=0) + title_para.alignment = WD_ALIGN_PARAGRAPH.CENTER + + # Process markdown content + i = 0 + in_code_block = False + in_table = False + table_lines = [] + + while i < len(lines): + line = lines[i].rstrip() + + # Skip frontmatter + if i == 0 and line.startswith('---'): + # Skip until next --- + i += 1 + while i < len(lines) and not lines[i].strip().startswith('---'): + i += 1 + i += 1 + continue + + # Code blocks + if line.startswith('```'): + if not in_code_block: + in_code_block = True + code_para = doc.add_paragraph() + code_para.style = 'No Spacing' + else: + in_code_block = False + i += 1 + continue + + if in_code_block: + code_para = doc.add_paragraph(line) + code_para.style = 'No Spacing' + for run in code_para.runs: + run.font.name = 'Courier New' + run.font.size = Pt(9) + i += 1 + continue + + # Tables + if line.startswith('|'): + if not in_table: + in_table = True + table_lines = [] + table_lines.append(line) + i += 1 + continue + elif in_table: + # End of table + in_table = False + rows = parse_markdown_table(table_lines) + add_table_to_doc(doc, rows) + doc.add_paragraph() # Spacing after table + table_lines = [] + + # Headings + if line.startswith('#'): + match = re.match(r'^(#{1,6})\s+(.+)$', line) + if match: + level = len(match.group(1)) + heading_text = match.group(2) + doc.add_heading(heading_text, level=min(level, 3)) + i += 1 + continue + + # Horizontal rules + if line.strip() in ['---', '***', '___']: + doc.add_paragraph('_' * 80) + i += 1 + continue + + # Bold text + if '**' in line: + para = doc.add_paragraph() + parts = re.split(r'(\*\*.*?\*\*)', line) + for part in parts: + if part.startswith('**') and part.endswith('**'): + run = para.add_run(part[2:-2]) + run.font.bold = True + else: + para.add_run(part) + i += 1 + continue + + # Lists + if re.match(r'^\s*[-*+]\s+', line): + # Bullet list + text = re.sub(r'^\s*[-*+]\s+', '', line) + doc.add_paragraph(text, style='List Bullet') + i += 1 + continue + + if re.match(r'^\s*\d+\.\s+', line): + # Numbered list + text = re.sub(r'^\s*\d+\.\s+', '', line) + doc.add_paragraph(text, style='List Number') + i += 1 + continue + + # Regular paragraphs + if line.strip(): + doc.add_paragraph(line) + else: + # Empty line - add spacing + doc.add_paragraph() + + i += 1 + + # Handle any remaining table + if in_table and table_lines: + rows = parse_markdown_table(table_lines) + add_table_to_doc(doc, rows) + + # Save document + doc.save(output_file) + print(f"✓ DOCX document created: {output_file}", file=sys.stderr) + print(f" Pages: Approximately {len(doc.paragraphs) // 40 + 1}", file=sys.stderr) + print(f" Sections: {len([p for p in doc.paragraphs if p.style.name.startswith('Heading')])}", file=sys.stderr) + + +def main(): + """Main entry point.""" + args = parse_arguments() + + # Validate input file exists + input_path = Path(args.input) + if not input_path.exists(): + print(f"Error: Input file not found: {args.input}", file=sys.stderr) + sys.exit(1) + + # Convert + try: + convert_markdown_to_docx(args.input, args.output, args.title) + except Exception as e: + print(f"Error converting markdown to DOCX: {e}", file=sys.stderr) + sys.exit(1) + + +if __name__ == "__main__": + main()