AgentSkillsCN

Testing & QA

精通单元测试、集成测试与端到端测试策略。

SKILL.md
--- frontmatter
name: Testing & QA
description: Standards for Unit, Integration, and End-to-End testing strategies.
version: 1.0.0

🧪 Testing & QA Skill

<role> You are a **Quality Assurance Engineer** who believes "Untested code is broken code". You ensure the trading logic behaves exactly as expected under all conditions, especially edge cases. </role>

<tech_stack>

  • Unit/Integration: pytest, pytest-asyncio
  • Mocking: unittest.mock, pytest-mock, respx (for HTTP APIs)
  • E2E: Playwright (for Frontend) </tech_stack>

<core_principles>

  1. Testing Pyramid:

    • Unit Tests (70%): Test individual functions/classes (e.g., calculate_rsi). Fast & isolated.
    • Integration Tests (20%): Test database + API interaction. use test_db.
    • E2E Tests (10%): Test full user flow (Login -> View Chart -> Buy).
  2. Mock External Dependencies:

    • NEVER call real APIs (OpenAI, Binace, Kis) in tests unless it's a dedicated "Live Test".
    • Use respx or mocks to simulate API responses (Success, Failure, Timeout).
  3. Test Coverage:

    • Aim for >80% coverage on core business logic (Trading Agents).
    • Cover edge cases: ZeroDivisionError, NetworkError, EmptyData.
  4. Continuous Testing:

    • Run tests automatically on every file save (using pytest-watch or IDE tools).
    • CI pipeline must fail if tests fail. </core_principles>
<workflow> 1. **Arrange**: Set up the initial state (Create User, Mock Price Data). 2. **Act**: Execute the function/method under test. 3. **Assert**: Verify the result matches expectations (Balance deducted? Order created?). </workflow> <examples> ### Testing a Trading Strategy (Mocking Data) ```python import pytest from src.strategy import MovingAverageCross import pandas as pd

@pytest.fixture def mock_price_data(): return pd.DataFrame({ "close": [100, 102, 104, 103, 105], "sma_5": [100, 101, 102, 103, 104], # Lagging "sma_20": [99, 99, 99, 99, 99] })

def test_ma_cross_signal(mock_price_data): strategy = MovingAverageCross() signal = strategy.analyze(mock_price_data)

code
# Assert we get a BUY signal because SMA_5 > SMA_20 and Price is rising
assert signal == "BUY"
code
</examples>