testing-patterns について
testing-patternsは、保守しやすいテストを書く開発者向けのスキルです。テスト構成、モック、フィクスチャ、統合テスト、カバレッジ目標を扱います。
主な機能
- 01AAAテスト構成
- 02外部サービスのモック
- 03フィクスチャとファクトリー
- 04統合テストのパターン
- 05カバレッジ目標
活用シーン
- 01ユニットテストの構成
- 02メールなどのサービスのモック
- 03再利用可能なテストデータの作成
- 04テストカバレッジ目標の設定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ langchain-ai/ skills-benchmarks --skill testing-patternsインストール後、Claude Code で/testing-patternsを入力して読み込まれたか確認します。
詳細
テストパターン
最新のパターンを使用して、効果的で保守しやすいテストを作成します。
テスト構造(AAA パターン)
def test_user_registration():
# Arrange
user_data = {"email": "[email protected]", "password": "secure123"}
# Act
result = register_user(user_data)
# Assert
assert result.success is True
assert result.user.email == "[email protected]"
外部サービスのモック
from unittest.mock import Mock, patch
@patch('services.email.send_email')
def test_sends_welcome_email(mock_send):
mock_send.return_value = True
register_user({"email": "[email protected]"})
mock_send.assert_called_once_with(
to="[email protected]",
template="welcome"
)
フィクスチャとファクトリー
import pytest
from factories import UserFactory
@pytest.fixture
def user():
return UserFactory.create(role="admin")
@pytest.fixture
def authenticated_client(user):
client = TestClient(app)
client.login(user)
return client
def test_admin_dashboard(authenticated_client):
response = authenticated_client.get("/admin")
assert response.status_code == 200
統合テスト
@pytest.mark.integration
def test_full_checkout_flow(db_session, stripe_mock):
# Create test data
user = create_user()
product = create_product(price=100)
# Execute flow
cart = add_to_cart(user, product)
order = checkout(cart, payment_method="card")
# Verify
assert order.status == "completed"
assert stripe_mock.charges.create.called
テストカバレッジの目標
- 単体テスト:カバレッジ 80% 以上
- 統合テスト:重要な経路
- E2E テスト:正常系のみ
コメント
Markdown 対応