test-automation
Test automation strategies and best practices
What this skill does
# Test Automation
## Test Automation Strategies
### Pyramid Approach
- **Unit Tests (70%)**: Fast, isolated tests for individual functions and methods
- **Integration Tests (20%)**: Tests that verify components work together
- **End-to-End Tests (10%)**: Tests that simulate real user flows through the application
### Risk-Based Testing
- Prioritize automation based on business risk and frequency of use
- Focus on critical paths and high-value features first
- Automate regression tests to prevent regressions
### Test Data Management
- **Fixtures**: Pre-defined test data sets for consistent test runs
- **Factories**: Dynamic test data generation for flexibility
- **Test Builders**: Fluent APIs for creating complex test objects
- **Data Seeding**: Database seeding for integration and E2E tests
## Test Design Patterns
### Page Object Model (POM)
- Encapsulate page elements and interactions in page objects
- Separate test logic from page interaction logic
- Improve test maintainability and reusability
- Example structure:
```javascript
class LoginPage {
constructor(page) {
this.page = page;
this.usernameInput = page.locator('#username');
this.passwordInput = page.locator('#password');
this.loginButton = page.locator('#login');
}
async login(username, password) {
await this.usernameInput.fill(username);
await this.passwordInput.fill(password);
await this.loginButton.click();
}
}
```
### Screenplay Pattern
- Actor-based testing with human-like interactions
- Composable abilities and tasks
- More readable and maintainable test scenarios
- Example structure:
```javascript
actor.attemptsTo(
Navigate.to('/login'),
Enter.theValue('username').into('#username'),
Enter.theValue('password').into('#password'),
Click.on('#login')
);
```
### Data-Driven Testing
- Separate test logic from test data
- Run same test with multiple data sets
- Use CSV, JSON, or database for test data
- Example structure:
```javascript
const testData = [
{ username: 'user1', password: 'pass1', expected: 'success' },
{ username: 'user2', password: 'pass2', expected: 'success' },
{ username: 'invalid', password: 'wrong', expected: 'failure' }
];
testData.forEach(({ username, password, expected }) => {
test(`login with ${username}`, async ({ page }) => {
await login(page, username, password);
await expect(page.locator('.status')).toHaveText(expected);
});
});
```
## Mocking and Stubbing Techniques
### When to Mock
- External API calls
- Database operations
- File system operations
- Time-dependent code
- Random number generation
### Mocking Best Practices
- Mock at boundaries, not within the system under test
- Keep mocks simple and realistic
- Verify mock interactions when necessary
- Use test doubles appropriately (stub, mock, spy, fake)
### Example Mocking (Jest)
```javascript
jest.mock('./api');
import { fetchUser } from './api';
test('fetches user data', async () => {
fetchUser.mockResolvedValue({ id: 1, name: 'Test User' });
const result = await getUser(1);
expect(result).toEqual({ id: 1, name: 'Test User' });
expect(fetchUser).toHaveBeenCalledWith(1);
});
```
## Test Isolation
### Preventing Test Interference
- Use fresh test data for each test
- Clean up after each test (teardown)
- Avoid shared state between tests
- Use test databases or transactions
### Database Isolation
- Wrap tests in database transactions and rollback
- Use in-memory databases for faster tests
- Seed test data before each test
- Clean up test data after each test
## Flaky Test Prevention
### Common Causes
- Race conditions and timing issues
- Dependency on external services
- Non-deterministic test data
- Browser state pollution
- Parallel test execution conflicts
### Prevention Strategies
- Use explicit waits instead of implicit waits
- Mock external dependencies
- Use deterministic test data
- Clear browser state between tests
- Configure tests to run sequentially when needed
- Retry flaky tests with proper investigation
## Test Reporting and Visualization
### Reporting Tools
- **Allure**: Comprehensive test reporting with history and trends
- **Mochawesome**: HTML reports for Mocha tests
- **Jest HTML Reporters**: Visual reports for Jest test suites
- **JUnit XML**: Standard format for CI/CD integration
### Key Metrics to Track
- Test execution time
- Pass/fail rates
- Flaky test rate
- Coverage trends
- Test failure patterns
### Dashboard Elements
- Overall test health
- Coverage metrics
- Test execution trends
- Flaky test alerts
- Failure analysis by category
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.