Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Complete testing strategy covering TDD workflow, test pyramid, unit/integration/E2E/property testing, framework best practices (Jest, Vitest, pytest), mock strategies, and CI integration. Use when writing tests, reviewing test quality, or establishing testing standards.
.claude/skills/majiayu000-comprehensive-testing/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 52% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 128% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 84% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 156% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 90% | 0% |
> Based on Anthropic's Claude Code Best Practices and community patterns
> "Claude performs best when it has a clear target to iterate against—a test case provides concrete success criteria."
Testing is not about proving code works; it's about designing code that is testable and documenting expected behavior.
/\
/ \ E2E Tests (10%)
/----\ - Full user flows
/ \ - Slowest, most brittle
/--------\
/ \ Integration Tests (20%)
/------------\ - Component interaction
/ \ - Real dependencies
/----------------\
Unit Tests (70%)
- Single function/method
- Fast, isolated, many| Level | Speed | Scope | When to Use | |-------|-------|-------|-------------| | Unit | <10ms | Single function | All logic | | Integration | <1s | Multiple components | APIs, DB | | E2E | <30s | Full flow | Critical paths |
1. WRITE TESTS FIRST
↓
2. VERIFY TESTS FAIL
↓
3. COMMIT TEST SUITE
↓
4. IMPLEMENT CODE
↓
5. VERIFY WITH SUBAGENT
↓
6. COMMIT IMPLEMENTATIONmarkdownBe EXPLICIT about TDD to avoid mock implementations: "I want to implement [feature] using TDD. First, write tests for [expected behavior] with these input/output pairs: - Input: X → Expected: Y - Input: A → Expected: B Do NOT create any implementation yet."
bash# Run tests and confirm they fail for the RIGHT reason npm test # or pytest, go test, etc. # Expected: "function not found" or "undefined" # NOT: syntax error, wrong import
bashgit add tests/ git commit -m "test: Add tests for [feature] (RED phase)"
markdown"Now implement the code to make these tests pass. Do NOT modify the tests. Run tests after each change until all pass."
Claude will enter an autonomous loop:
Write code → Run tests → Analyze failures → Adjust → Repeatmarkdown"Use a subagent to independently verify the implementation: - Is it overfitting to tests? - Are edge cases handled? - Is the code maintainable?"
bashgit add src/ git commit -m "feat: Implement [feature] (GREEN phase)"
typescriptdescribe('UserService', () => { it('should create user with valid email', async () => { // Arrange - Setup test data and dependencies const userRepo = new InMemoryUserRepository(); const service = new UserService(userRepo); const input = { email: 'test@example.com', name: 'Test' }; // Act - Execute the code under test const user = await service.create(input); // Assert - Verify the results expect(user.email).toBe('test@example.com'); expect(user.id).toBeDefined(); expect(await userRepo.findById(user.id)).toEqual(user); }); });
pythondef test_order_total_with_discount(): """ Given an order with items totaling $100 When a 20% discount is applied Then the total should be $80 """ # Given order = Order() order.add_item(Item(price=50)) order.add_item(Item(price=50)) # When order.apply_discount(Percentage(20)) # Then assert order.total == Money(80)
typescript// Structure describe('ModuleName', () => { describe('methodName', () => { it('should [expected behavior] when [condition]', () => {}); }); }); // Setup/Teardown beforeAll(async () => { /* one-time setup */ }); beforeEach(() => { /* per-test setup */ }); afterEach(() => { /* per-test cleanup */ }); afterAll(async () => { /* one-time cleanup */ }); // Async testing it('handles async operations', async () => { const result = await asyncFunction(); expect(result).toBe(expected); }); // Error testing it('throws on invalid input', () => { expect(() => validate(null)).toThrow('Input required'); }); // Snapshot testing (use sparingly) it('renders correctly', () => { const tree = renderer.create(<Component />).toJSON(); expect(tree).toMatchSnapshot(); }); // Table-driven tests it.each([ [1, 1, 2], [2, 2, 4], [0, 0, 0], ])('add(%i, %i) = %i', (a, b, expected) => { expect(add(a, b)).toBe(expected); });
vitest.config.ts:
typescriptexport default defineConfig({ test: { globals: true, environment: 'node', coverage: { provider: 'v8', reporter: ['text', 'json', 'html'], thresholds: { lines: 80, branches: 70, functions: 80, }, }, }, });
pythonimport pytest from mymodule import Calculator # Fixtures for dependency injection @pytest.fixture def calculator(): return Calculator() @pytest.fixture def database(): db = TestDatabase() yield db db.cleanup() # Parametrized tests @pytest.mark.parametrize("a,b,expected", [ (1, 1, 2), (2, 2, 4), (0, 0, 0), (-1, 1, 0), ]) def test_add(calculator, a, b, expected): assert calculator.add(a, b) == expected # Exception testing def test_divide_by_zero(calculator): with pytest.raises(ZeroDivisionError): calculator.divide(1, 0) # Async testing @pytest.mark.asyncio async def test_async_operation(): result = await async_function() assert result == expected # Markers for categorization @pytest.mark.slow @pytest.mark.integration def test_database_connection(database): assert database.is_connected()
conftest.py:
pythonimport pytest @pytest.fixture(scope="session") def database_url(): return "postgresql://test:test@localhost/test" @pytest.fixture(autouse=True) def reset_database(database): yield database.rollback()
pytest.ini:
ini[pytest] testpaths = tests python_files = test_*.py python_functions = test_* addopts = -v --cov=src --cov-report=term-missing markers = slow: marks tests as slow integration: marks tests as integration tests
gopackage mypackage import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAdd(t *testing.T) { tests := []struct { name string a, b int expected int }{ {"positive numbers", 1, 2, 3}, {"zero values", 0, 0, 0}, {"negative numbers", -1, -2, -3}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := Add(tt.a, tt.b) assert.Equal(t, tt.expected, result) }) } } // Table-driven with subtests func TestUserService_Create(t *testing.T) { t.Run("creates user with valid input", func(t *testing.T) { repo := NewInMemoryRepo() svc := NewUserService(repo) user, err := svc.Create(CreateUserInput{Email: "test@example.com"}) require.NoError(t, err) assert.NotEmpty(t, user.ID) assert.Equal(t, "test@example.com", user.Email) }) t.Run("returns error for invalid email", func(t *testing.T) { repo := NewInMemoryRepo() svc := NewUserService(repo) _, err := svc.Create(CreateUserInput{Email: "invalid"}) require.Error(t, err) assert.Contains(t, err.Error(), "invalid email") }) }
| Scenario | Mock? | Reason | |----------|-------|--------| | External APIs | ✅ Yes | Slow, unreliable, costs money | | Time/Date | ✅ Yes | Non-deterministic | | Random | ✅ Yes | Non-deterministic | | Database (unit) | ✅ Yes | Slow, complex setup | | Database (integration) | ❌ No | Test real behavior | | Your own code | ⚠️ Rarely | Prefer real implementations | | File system | ⚠️ Depends | Use temp dirs when possible |
typescript// Jest - Mock module jest.mock('./emailService', () => ({ sendEmail: jest.fn().mockResolvedValue({ success: true }), })); // Jest - Mock function const mockCallback = jest.fn(); mockCallback.mockReturnValue(42); // Vitest - Spy import { vi } from 'vitest'; const spy = vi.spyOn(console, 'log'); // Time mocking beforeEach(() => { vi.useFakeTimers(); vi.setSystemTime(new Date('2024-01-01')); }); afterEach(() => { vi.useRealTimers(); });
python# pytest - Mock with unittest.mock from unittest.mock import Mock, patch, MagicMock @patch('mymodule.external_api.fetch') def test_with_mocked_api(mock_fetch): mock_fetch.return_value = {'data': 'mocked'} result = my_function() assert result == expected mock_fetch.assert_called_once_with('expected_arg') # Fixture-based mock @pytest.fixture def mock_email_service(): service = Mock() service.send.return_value = True return service
typescript// ❌ Heavy mocking const mockRepo = { findById: jest.fn().mockResolvedValue({ id: '1', name: 'Test' }), save: jest.fn().mockResolvedValue(undefined), delete: jest.fn().mockResolvedValue(undefined), }; // ✅ In-memory implementation (test double) class InMemoryUserRepository implements UserRepository { private users: Map<string, User> = new Map(); async findById(id: string): Promise<User | null> { return this.users.get(id) || null; } async save(user: User): Promise<User> { this.users.set(user.id, user); return user; } async delete(id: string): Promise<void> { this.users.delete(id); } }
Detailed material starting at ## Boundary Testing has been moved to reference/extended.md to keep this skill concise. Load that reference when the task requires the moved examples, command catalogs, checklists, platform details, or implementation templates.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-03 | pass→pass | 9,707 | 5,270 | -46% | 1 | 1 | 0% | 1,480 | 3,792 | +156% | 0 | 0 | — |
case-04 | fail→fail | 12,237 | 8,627 | -30% | 1 | 1 | 0% | 2,032 | 4,484 | +121% | 0 | 0 | — |
case-01 | fail→pass | 20,716 | 22,966 | +11% | 1 | 1 | 0% | 4,267 | 6,488 | +52% | 0 | 0 | — |
case-02 | pass→pass | 13,887 | 7,609 | -45% | 1 | 1 | 0% | 2,227 | 4,240 | +90% | 0 | 0 | — |
case-05 | pass→pass | 13,467 | 13,968 | +4% | 1 | 1 | 0% | 2,136 | 5,033 | +136% | 0 | 0 | — |
case-06 | pass→pass | 14,368 | 15,948 | +11% | 1 | 1 | 0% | 2,211 | 5,662 | +156% | 0 | 0 | — |
case-07 | pass→pass | 15,044 | 13,691 | -9% | 1 | 1 | 0% | 2,641 | 5,472 | +107% | 0 | 0 | — |
case-08 | pass→pass | 11,906 | 13,072 | +10% | 1 | 1 | 0% | 2,364 | 5,659 | +139% | 0 | 0 | — |
case-09 | pass→pass | 3,848 | 5,119 | +33% | 1 | 1 | 0% | 677 | 3,926 | +480% | 0 | 0 | — |
case-10 | fail→pass | 11,006 | 8,995 | -18% | 1 | 1 | 0% | 2,052 | 4,680 | +128% | 0 | 0 | — |
case-11 | pass→pass | 4,847 | 5,010 | +3% | 1 | 1 | 0% | 879 | 3,906 | +344% | 0 | 0 | — |
case-12 | pass→pass | 14,134 | 11,894 | -16% | 1 | 1 | 0% | 2,200 | 4,854 | +121% | 0 | 0 | — |
case-17 | pass→pass | 2,787 | 2,820 | +1% | 1 | 1 | 0% | 496 | 3,412 | +588% | 0 | 0 | — |
case-13 | pass→pass | 10,301 | 5,885 | -43% | 1 | 1 | 0% | 1,789 | 4,034 | +125% | 0 | 0 | — |
case-14 | pass→pass | 8,263 | 4,899 | -41% | 1 | 1 | 0% | 1,365 | 3,780 | +177% | 0 | 0 | — |
case-15 | pass→pass | 11,309 | 10,000 | -12% | 1 | 1 | 0% | 1,899 | 4,610 | +143% | 0 | 0 | — |
case-16 | pass→pass | 12,448 | 9,391 | -25% | 1 | 1 | 0% | 1,916 | 4,368 | +128% | 0 | 0 | — |
case-18 | pass→pass | 14,291 | 13,940 | -2% | 1 | 1 | 0% | 2,559 | 5,467 | +114% | 0 | 0 | — |
case-19 | fail→pass | 12,110 | 2,779 | -77% | 1 | 1 | 0% | 1,857 | 3,420 | +84% | 0 | 0 | — |
case-20 | pass→pass | 12,876 | 12,872 | -0% | 1 | 1 | 0% | 2,275 | 5,272 | +132% | 0 | 0 | — |
case-21 | pass→pass | 12,670 | 9,524 | -25% | 1 | 1 | 0% | 2,018 | 4,616 | +129% | 0 | 0 | — |
case-22 | pass→pass | 9,158 | 11,528 | +26% | 1 | 1 | 0% | 1,717 | 5,144 | +200% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.