Load when editing test_*, *.test.*, or *_test.py files, or working with pytest/jest frameworks. Provides testing patterns for Python and TypeScript projects.
📖 中文导读:Load when editing test_*, *.test.*, or *_test.py files, or working with pytest/jest frameworks. Provides testing patterns for Python and TypeScript projects. 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: testing
description: Load when editing test_*, .test., or *_test.py files, or working with pytest/jest frameworks. Provides testing patterns for Python and TypeScript projects.
Testing
Merged Skills
pytest: Python testing with async support
jest: TypeScript/React component testing
e2e: End-to-end integration testing
⚠️ Critical Gotchas
Category
Pattern
Solution
Async fixtures
Fixture not async
Use @pytest.fixture with async def
Over-mocking
Everything mocked
Only mock at service boundaries
Flaky tests
Random failures
Add pytest.mark.flaky or fix race condition
E2E timing
Tests fail intermittently
Use explicit waits, not sleep()
Shared state
Tests affect each other
Fresh setup each test, isolate state
Wrong level
Unit test for integration
Match test type to what you're testing
Rules
Rule
Pattern
Test behavior
Test what it does, not how
Isolate tests
No shared state between tests
Fast first
Run API/UI tests before E2E
Meaningful names
Describe expected behavior in test name
E2E confirms
Only run E2E after API+UI pass
Mock boundaries
Mock external services, not internal logic
Avoid
❌ Bad
✅ Good
Testing implementation
Testing behavior
Shared state
Fresh setup each test
Mock everything
Mock boundaries only
E2E for unit logic
E2E for user flows
time.sleep() in E2E
Explicit waits
Generic test names
test_create_script_returns_201
Testing Hierarchy
Level
Target
When
Command
1. API
Backend endpoints
After API changes
pytest backend/tests/api/
2. UI
Components, pages
After frontend changes
npm test
3. E2E
Full flow
Final confirmation
pytest backend/tests/e2e/ -m e2e
Patterns
# Pattern 1: API test with async client
class TestScriptAPI:
async def test_create_script_returns_201(self, client):
response = await client.post("/api/scripts/", json={"name": "test"})
assert response.status_code == 201
assert response.json()["id"] is not None
async def test_list_scripts_returns_all(self, client, sample_scripts):
response = await client.get("/api/scripts/")
assert len(response.json()) == len(sample_scripts)
# Pattern 2: Async fixture
@pytest.fixture
async def sample_scripts(db_session):
scripts = [Script(name=f"script_{i}") for i in range(3)]
db_session.add_all(scripts)
await db_session.commit()
return scripts