Testing Skill
When working on testing tasks, follow these guidelines:
Test Generation Approach
1. Understand the Code
- Analyze the function/module to be tested
- Identify inputs, outputs, and side effects
- Note dependencies and external interactions
- Understand the business logic and requirements
2. Test Categories
Unit Tests
- Test individual functions/methods in isolation
- Mock external dependencies
- Focus on single responsibility
- Fast execution
Integration Tests
- Test component interactions
- Use real or test doubles for dependencies
- Verify data flow between modules
- Test API endpoints with actual calls
End-to-End Tests
- Test complete user workflows
- Use real or staging environment
- Validate from user perspective
- Cover critical business paths
3. Test Coverage
Ensure tests cover:
- Happy Path: Normal, expected inputs and flows
- Edge Cases: Boundary values, empty inputs, maximum values
- Error Cases: Invalid inputs, missing data, exceptions
- State Changes: Before/after state verification
- Side Effects: Database changes, API calls, file operations
4. Test Structure (AAA Pattern)
// Arrange: Set up test data and conditions
// Act: Execute the code under test
// Assert: Verify the results
5. Best Practices
- Clear Names: Test names should describe what's being tested and expected behavior
- Format:
test_[method]_[scenario]_[expectedResult]
- Example:
test_calculateTotal_withDiscount_returnsReducedAmount
- One Assert Per Test: Each test should verify one behavior
- Independent Tests: Tests should not depend on each other
- Fast Tests: Keep unit tests fast (< 100ms)
- Reliable Tests: No flaky tests, no random data without seeds
- Maintainable: Easy to understand and update
6. Testing Frameworks
Adapt to the project's testing framework:
- JavaScript/TypeScript: Jest, Mocha, Vitest, Cypress
- Python: pytest, unittest, nose2
- Java: JUnit, TestNG, Mockito
- C#: NUnit, xUnit, MSTest
- .NET: xUnit, NUnit
- Go: testing package, testify
- Ruby: RSpec, Minitest
7. Mocking Strategy
- Mock external dependencies (APIs, databases, file system)
- Use test doubles appropriately:
- Mocks: Verify interactions
- Stubs: Provide predetermined responses
- Fakes: Simplified working implementations
- Spies: Record information about calls
8. Output Format
When generating tests, provide:
- Test file location and name
- Necessary imports and setup
- Complete test cases with:
- Descriptive names
- Arrange/Act/Assert sections
- Comments explaining complex scenarios
- Coverage summary: What's tested, what's not
- Running instructions: How to execute tests
Code Coverage Goals
- Minimum: 70% overall coverage
- Target: 80%+ for critical business logic
- Focus: Quality over quantity - meaningful tests, not just coverage numbers
When Improving Existing Tests
- Analyze current coverage: Identify gaps
- Review existing tests: Check for anti-patterns
- Prioritize: Start with critical paths and low-coverage areas
- Refactor: Make tests more maintainable
- Document: Add comments for complex test scenarios
1---2name: testing3description: Generate comprehensive test cases, improve test coverage, and create testing strategies for unit, integration, and e2e tests4---56# Testing Skill78When working on testing tasks, follow these guidelines:910## Test Generation Approach1112### 1. Understand the Code13- Analyze the function/module to be tested14- Identify inputs, outputs, and side effects15- Note dependencies and external interactions16- Understand the business logic and requirements1718### 2. Test Categories1920#### Unit Tests21- Test individual functions/methods in isolation22- Mock external dependencies23- Focus on single responsibility24- Fast execution2526#### Integration Tests27- Test component interactions28- Use real or test doubles for dependencies29- Verify data flow between modules30- Test API endpoints with actual calls3132#### End-to-End Tests33- Test complete user workflows34- Use real or staging environment35- Validate from user perspective36- Cover critical business paths3738### 3. Test Coverage3940Ensure tests cover:41- **Happy Path**: Normal, expected inputs and flows42- **Edge Cases**: Boundary values, empty inputs, maximum values43- **Error Cases**: Invalid inputs, missing data, exceptions44- **State Changes**: Before/after state verification45- **Side Effects**: Database changes, API calls, file operations4647### 4. Test Structure (AAA Pattern)4849```50// Arrange: Set up test data and conditions51// Act: Execute the code under test52// Assert: Verify the results53```5455### 5. Best Practices5657- **Clear Names**: Test names should describe what's being tested and expected behavior58 - Format: `test_[method]_[scenario]_[expectedResult]`59 - Example: `test_calculateTotal_withDiscount_returnsReducedAmount`60- **One Assert Per Test**: Each test should verify one behavior61- **Independent Tests**: Tests should not depend on each other62- **Fast Tests**: Keep unit tests fast (< 100ms)63- **Reliable Tests**: No flaky tests, no random data without seeds64- **Maintainable**: Easy to understand and update6566### 6. Testing Frameworks6768Adapt to the project's testing framework:69- **JavaScript/TypeScript**: Jest, Mocha, Vitest, Cypress70- **Python**: pytest, unittest, nose271- **Java**: JUnit, TestNG, Mockito72- **C#**: NUnit, xUnit, MSTest73- **.NET**: xUnit, NUnit74- **Go**: testing package, testify75- **Ruby**: RSpec, Minitest7677### 7. Mocking Strategy7879- Mock external dependencies (APIs, databases, file system)80- Use test doubles appropriately:81 - **Mocks**: Verify interactions82 - **Stubs**: Provide predetermined responses83 - **Fakes**: Simplified working implementations84 - **Spies**: Record information about calls8586### 8. Output Format8788When generating tests, provide:89901. **Test file location and name**912. **Necessary imports and setup**923. **Complete test cases with:**93 - Descriptive names94 - Arrange/Act/Assert sections95 - Comments explaining complex scenarios964. **Coverage summary**: What's tested, what's not975. **Running instructions**: How to execute tests9899## Code Coverage Goals100101- **Minimum**: 70% overall coverage102- **Target**: 80%+ for critical business logic103- **Focus**: Quality over quantity - meaningful tests, not just coverage numbers104105## When Improving Existing Tests1061071. **Analyze current coverage**: Identify gaps1082. **Review existing tests**: Check for anti-patterns1093. **Prioritize**: Start with critical paths and low-coverage areas1104. **Refactor**: Make tests more maintainable1115. **Document**: Add comments for complex test scenarios