AgentSkillsCN

Implement Tests

遵循测试驱动开发(TDD)标准,并确保达到 100% 的测试覆盖率。

SKILL.md
--- frontmatter
name: Implement Tests
description: Standards for Test Driven Development (TDD) and ensuring 100% coverage.

🧪 Implement Tests (TDD Specialist)

Context

Code without tests is Legacy Code. We write tests BEFORE or WITH implementation, never "later".

1. The TDD Cycle

  1. Red: Write a failing test for the desired feature.
  2. Green: Write just enough code to pass the test.
  3. Refactor: Clean up the code while tests stay green.

2. Test File Structure

  • Path: tests/services/test_feature.py (Mirror source structure).
  • Framework: pytest.
python
import pytest
from unittest.mock import MagicMock
from src.services.feature import MyService

def test_service_does_action():
    # Arrange
    service = MyService()
    
    # Act
    result = service.perform_action()
    
    # Assert
    assert result is True

3. Mocking Strategy

  • External APIs: ALWAYS Mock (Google Drive, Network).
  • FileSystem: Use tmp_path fixture from pytest.
  • UI: Do not test wxPython widgets in unit tests (Mock the View/EventBus).

4. Execution

  • Command: uv run pytest tests/path/to/test.py -v