AgentSkillsCN

testing-patterns

适用于Lupin项目的测试模式。当您编写测试用例、运行pytest、调试测试失败问题、在冒烟测试、单元测试与集成测试之间做出选择、检查测试覆盖率,或修复未能通过的测试时,均可采用此模式。

SKILL.md
--- frontmatter
name: testing-patterns
description: Testing patterns for Lupin project. Use when writing tests, running pytest, debugging test failures, choosing between smoke/unit/integration tests, checking test coverage, or fixing failing tests.
metadata:
  author: lupin-team
  version: "1.0"
  last-updated: "2026-01-28"

Testing Patterns

Lupin uses a three-tier testing strategy for comprehensive validation.

Test Tiers Overview

TierLocationSpeedPurposeRun Command
Unitsrc/tests/unit/1-10msIsolated functionspytest src/tests/unit/
Smokeinline quick_smoke_test()10-100msModule sanitypython -m cosa.rest.jwt_service
Integrationsrc/tests/integration/100-1000msEnd-to-end flows./src/tests/run-integration-tests.sh -v
WebSocketsrc/tests/websocket_smoke/variesWS functionalitysrc/scripts/run-websocket-smoke-tests.sh

Quick Commands

bash
# Integration tests (RECOMMENDED - handles server automatically)
./src/tests/run-integration-tests.sh -v              # All integration
./src/tests/run-integration-tests.sh -v -s           # Very verbose
./src/tests/run-integration-tests.sh test_auth*.py   # Specific pattern

# Unit tests
pytest src/tests/unit/                               # All unit tests
pytest -v src/tests/unit/                            # Verbose

# All pytest tests (requires manual server setup)
pytest src/tests/

# With coverage
pytest --cov=cosa.rest --cov-report=html src/tests/

# WebSocket tests
src/scripts/run-websocket-smoke-tests.sh

Which Test Type to Use?

ScenarioUse
Testing a single functionUnit test
Checking module loadsSmoke test
Testing API endpoint flowIntegration test
Testing WebSocket eventsWebSocket test
Testing with databaseIntegration test
Testing auth flowIntegration test

Critical Rules

  1. Integration tests require running server - Use the script, it handles this
  2. Unit tests mock dependencies - Don't hit real database/APIs
  3. Smoke tests are quick sanity checks - Not comprehensive
  4. WebSocket tests have separate runner - Don't mix with pytest

Test Coverage

AreaCoverageTests
Auth System85-90%14+ unit, 43 integration
WebSocket92% pass50 tests
Total~122 testsunit + smoke + integration + WS

Documentation

  • Full Guide: src/tests/README.md
  • Integration: src/tests/integration/README.md
  • Unit Tests: Inline documentation in test files

Anti-Patterns

  • Don't run integration tests without the wrapper script
  • Don't test external APIs in unit tests (use mocks)
  • Don't skip smoke tests - they catch major breakage fast
  • Don't mix WebSocket tests with regular pytest runs