AI Skill Report Card
Writing Automated Tests
Quick Start
JavaScript// Example: Testing a user registration function const { createUser, validateEmail } = require('./user-service'); describe('User Registration', () => { test('creates user with valid data', async () => { const userData = { email: 'test@example.com', password: 'SecurePass123!' }; const user = await createUser(userData); expect(user.id).toBeDefined(); expect(user.email).toBe('test@example.com'); expect(user.password).not.toBe(userData.password); // Should be hashed }); test('rejects invalid email formats', () => { expect(validateEmail('invalid-email')).toBe(false); expect(validateEmail('test@example.com')).toBe(true); }); });
Recommendation▾
Add concrete input/output examples showing actual test results (passed/failed) rather than just code snippets
Workflow
Progress:
- Set up testing framework (Jest, pytest, etc.)
- Configure static analysis tools (TypeScript, ESLint, mypy)
- Write unit tests for core business logic
- Add integration tests for critical user flows
- Set up automated test runs in CI/CD
- Monitor test coverage and maintenance burden
Test Writing Process:
- Start with static typing - Use TypeScript, Python type hints, or similar
- Add linting - ESLint, pylint, or language-specific tools
- Test business logic first - Focus on functions that contain your core rules
- Test error conditions - Invalid inputs, network failures, edge cases
- Integration tests last - Full user flows, database interactions
Recommendation▾
Include a template or framework section with ready-to-use test structure patterns for different scenarios
Examples
Example 1: Unit Test Input: Payment processing function Output:
Pythondef test_process_payment(): # Happy path result = process_payment(100.00, "valid_card_token") assert result.success == True assert result.transaction_id is not None # Error cases with pytest.raises(InvalidAmountError): process_payment(-10.00, "valid_card_token")
Example 2: Integration Test Input: User checkout flow Output:
JavaScripttest('complete checkout process', async () => { const user = await createTestUser(); const product = await createTestProduct(); await addToCart(user.id, product.id); const order = await checkout(user.id, testPaymentMethod); expect(order.status).toBe('completed'); expect(order.total).toBe(product.price); });
Recommendation▾
Expand the workflow checklist to include specific criteria for when each type of test is complete
Best Practices
- Confidence over coverage - 100% coverage doesn't mean bug-free code
- Test behavior, not implementation - Focus on what the code should do, not how
- Keep tests simple - Each test should verify one specific behavior
- Use descriptive test names -
should_reject_expired_credit_cardsnottest_payment - Fast feedback loop - Unit tests should run in seconds, not minutes
- Mock external dependencies - Don't hit real APIs or databases in unit tests
Common Pitfalls
- Testing framework code - Don't test library functions, test YOUR logic
- Brittle tests - Tests that break when you refactor working code
- Testing too much implementation detail - Mock every single function call
- Ignoring edge cases - Empty arrays, null values, boundary conditions
- No static analysis - Writing tests without TypeScript/linting is doing it the hard way
- All or nothing mentality - Start small, add tests incrementally to existing projects