본문으로 건너뛰기
cccskills
무료GitHub에 공개

api-testing

REST/GraphQL API testing with automated validation — test endpoints, validate responses, check status codes, and ensure API contracts

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

API Testing — Automated Endpoint Validation

Test REST and GraphQL APIs with automated validation. Verify endpoints, status codes, response schemas, performance, and security. Ensure API contracts are maintained across changes.

When to Use

  • Testing REST/GraphQL endpoints
  • Validating API responses
  • Contract testing between services
  • Performance testing APIs
  • Security testing endpoints
  • CI/CD API validation

Testing Approaches

1. Manual Testing (curl)

# GET request
curl -X GET https://api.example.com/users

# POST with JSON
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name": "John", "email": "john@example.com"}'

# With authentication
curl -X GET https://api.example.com/profile \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

# Save response
curl -X GET https://api.example.com/users -o response.json

# Show headers
curl -i https://api.example.com/users

# Verbose output
curl -v https://api.example.com/users

2. Automated Testing (Python + requests + pytest)

import requests
import pytest

BASE_URL = "https://api.example.com"

def test_get_users():
    response = requests.get(f"{BASE_URL}/users")
    
    # Status code
    assert response.status_code == 200
    
    # Response structure
    data = response.json()
    assert isinstance(data, list)
    assert len(data) > 0
    
    # First user structure
    user = data[0]
    assert "id" in user
    assert "name" in user
    assert "email" in user

def test_create_user():
    payload = {
        "name": "John Doe",
        "email": "john@example.com"
    }
    
    response = requests.post(
        f"{BASE_URL}/users",
        json=payload
    )
    
    assert response.status_code == 201
    data = response.json()
    assert data["name"] == payload["name"]
    assert data["email"] == payload["email"]
    assert "id" in data

def test_authentication_required():
    response = requests.get(f"{BASE_URL}/profile")
    assert response.status_code == 401

def test_invalid_data():
    payload = {"name": ""}  # Invalid: empty name
    response = requests.post(
        f"{BASE_URL}/users",
        json=payload
    )
    assert response.status_code == 400
    assert "error" in response.json()

def test_not_found():
    response = requests.get(f"{BASE_URL}/users/99999")
    assert response.status_code == 404

3. Schema Validation (jsonschema)

import requests
from jsonschema import validate

user_schema = {
    "type": "object",
    "properties": {
        "id": {"type": "integer"},
        "name": {"type": "string"},
        "email": {"type": "string", "format": "email"},
        "created_at": {"type": "string", "format": "date-time"}
    },
    "required": ["id", "name", "email"]
}

def test_user_schema():
    response = requests.get(f"{BASE_URL}/users/1")
    data = response.json()
    
    # Validate against schema
    validate(instance=data, schema=user_schema)

4. GraphQL Testing

def test_graphql_query():
    query = """
    query {
        users {
            id
            name
            email
        }
    }
    """
    
    response = requests.post(
        f"{BASE_URL}/graphql",
        json={"query": query}
    )
    
    assert response.status_code == 200
    data = response.json()
    assert "data" in data
    assert "users" in data["data"]
    assert len(data["data"]["users"]) > 0

Testing Patterns

1. Setup/Teardown

import pytest

@pytest.fixture
def test_user():
    """Create test user, cleanup after test"""
    # Setup
    response = requests.post(
        f"{BASE_URL}/users",
        json={"name": "Test User", "email": "test@example.com"}
    )
    user = response.json()
    
    yield user
    
    # Teardown
    requests.delete(f"{BASE_URL}/users/{user['id']}")

def test_with_fixtures(test_user):
    response = requests.get(f"{BASE_URL}/users/{test_user['id']}")
    assert response.status_code == 200

2. Parametrized Tests

@pytest.mark.parametrize("endpoint,expected_status", [
    ("/users", 200),
    ("/posts", 200),
    ("/comments", 200),
    ("/invalid", 404),
])
def test_endpoints(endpoint, expected_status):
    response = requests.get(f"{BASE_URL}{endpoint}")
    assert response.status_code == expected_status

3. Performance Testing

import time

def test_response_time():
    start = time.time()
    response = requests.get(f"{BASE_URL}/users")
    duration = time.time() - start
    
    assert response.status_code == 200
    assert duration < 1.0  # Must respond within 1 second

4. Contract Testing

def test_api_contract():
    """Ensure API contract hasn't changed"""
    response = requests.get(f"{BASE_URL}/users/1")
    user = response.json()
    
    # Required fields must exist
    required_fields = ["id", "name", "email", "created_at"]
    for field in required_fields:
        assert field in user, f"Missing required field: {field}"
    
    # Field types must match
    assert isinstance(user["id"], int)
    assert isinstance(user["name"], str)
    assert isinstance(user["email"], str)

Best Practices

1. Test Error Cases

def test_error_cases():
    # Invalid data
    response = requests.post(f"{BASE_URL}/users", json={})
    assert response.status_code == 400
    
    # Unauthorized
    response = requests.get(f"{BASE_URL}/profile")
    assert response.status_code == 401
    
    # Not found
    response = requests.get(f"{BASE_URL}/users/99999")
    assert response.status_code == 404

2. Test Pagination

def test_pagination():
    response = requests.get(f"{BASE_URL}/users?page=1&limit=10")
    data = response.json()
    
    assert "items" in data
    assert "total" in data
    assert "page" in data
    assert len(data["items"]) <= 10

Running Tests

# Run all tests
pytest tests/api/

# Run with coverage
pytest tests/api/ --cov

# Run specific test
pytest tests/api/test_users.py::test_get_users

# Run with verbose output
pytest tests/api/ -v

References

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Drives development with tests. Use when implementing any logic, fixing any bug, or changing any behavior. Use when you need to prove that code works, when a bug report arrives, or when you're about to modify existing functionality.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

kevinnft/ai-agent-skills142026년 8월 1일 업데이트

airtable

무료

Airtable REST API via curl. Records CRUD, filters, upserts.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

kevinnft/ai-agent-skills142026년 8월 1일 업데이트

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

kevinnft/ai-agent-skills142026년 8월 1일 업데이트

Build monitoring bots that poll APIs and send notifications on state changes (new listings, price alerts, status updates)

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

kevinnft/ai-agent-skills142026년 8월 1일 업데이트

Manage Apple Notes via memo CLI: create, search, edit.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

kevinnft/ai-agent-skills142026년 8월 1일 업데이트

Apple Reminders via remindctl: add, list, complete.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

kevinnft/ai-agent-skills142026년 8월 1일 업데이트

kevinnft의 스킬 모두 보기

이 스킬의 문제 신고