$npx -y skills add LambdaTest/agent-skills --skill api-to-testcase-generatorAutomatically generate comprehensive test cases from API definitions, endpoint descriptions, OpenAPI/Swagger specs, Postman collections, or raw HTTP request/response examples. Use this skill whenever the user mentions generating tests from APIs, writing test cases for REST endpoi
| 1 | # API-to-Test Case Generator |
| 2 | |
| 3 | Converts API definitions into production-ready test suites covering happy paths, edge cases, |
| 4 | error handling, and boundary conditions. |
| 5 | |
| 6 | --- |
| 7 | |
| 8 | ## Supported Input Formats |
| 9 | |
| 10 | | Format | Example | |
| 11 | |---|---| |
| 12 | | OpenAPI 3.x YAML/JSON | `openapi: 3.0.0` | |
| 13 | | Swagger 2.0 | `swagger: "2.0"` | |
| 14 | | Postman Collection v2.x | JSON export from Postman | |
| 15 | | Raw curl commands | `curl -X POST https://...` | |
| 16 | | Plain English description | "POST /users creates a user with name and email" | |
| 17 | | HTTP request/response examples | Paste raw request + response | |
| 18 | | Code (route handlers / controllers) | Express.js, FastAPI, Spring, etc. | |
| 19 | |
| 20 | --- |
| 21 | |
| 22 | ## Supported Test Frameworks |
| 23 | |
| 24 | | Language | Frameworks | |
| 25 | |---|---| |
| 26 | | Python | `pytest` + `requests` or `httpx` | |
| 27 | | JavaScript/TypeScript | `Jest`, `Mocha`/`Chai`, `Supertest` | |
| 28 | | Java | `JUnit 5` + `RestAssured` | |
| 29 | | Go | `testing` + `net/http/httptest` | |
| 30 | | API-level (language-agnostic) | `Newman` (Postman), `k6` (load), plain `.http` files | |
| 31 | |
| 32 | If the user doesn't specify a framework, **ask** — or default to `pytest` for Python APIs, `Jest` for JS/TS APIs. |
| 33 | |
| 34 | --- |
| 35 | |
| 36 | ## Workflow |
| 37 | |
| 38 | ### Step 1 — Parse the API Definition |
| 39 | |
| 40 | Extract from the input: |
| 41 | - **Endpoints**: method + path (e.g., `POST /api/v1/users`) |
| 42 | - **Request**: headers, query params, path params, body schema (required vs optional fields, types) |
| 43 | - **Response**: status codes, response body schema, headers |
| 44 | - **Auth**: Bearer token, API key, Basic auth, OAuth2 |
| 45 | - **Constraints**: min/max, enum values, format (email, uuid, date-time), nullable |
| 46 | |
| 47 | If input is ambiguous or incomplete, ask the user to clarify before generating. |
| 48 | |
| 49 | ### Step 2 — Determine Test Strategy |
| 50 | |
| 51 | For each endpoint, generate tests across these categories: |
| 52 | |
| 53 | #### ✅ Happy Path Tests |
| 54 | - Valid request with all required fields → expect `2xx` |
| 55 | - Valid request with all optional fields included |
| 56 | - Minimal valid request (required fields only) |
| 57 | |
| 58 | #### ❌ Validation / Error Tests |
| 59 | - Missing required fields → expect `400`/`422` |
| 60 | - Invalid field types (string where int expected, etc.) |
| 61 | - Out-of-range values (below min, above max) |
| 62 | - Invalid enum values |
| 63 | - Malformed request body (invalid JSON) |
| 64 | - Extra/unknown fields (if strict validation expected) |
| 65 | |
| 66 | #### 🔒 Auth / Authorization Tests |
| 67 | - No auth token → expect `401` |
| 68 | - Invalid/expired token → expect `401` |
| 69 | - Insufficient permissions → expect `403` |
| 70 | - Valid token → expect success |
| 71 | |
| 72 | #### 🔍 Edge Cases |
| 73 | - Empty string / null for optional fields |
| 74 | - Maximum-length strings |
| 75 | - Boundary values (min, max, min-1, max+1) |
| 76 | - Special characters in string fields |
| 77 | - Idempotency (repeat same request — does it behave correctly?) |
| 78 | |
| 79 | #### 🌐 Integration / Flow Tests (when multiple endpoints provided) |
| 80 | - Create → Read → Update → Delete flows |
| 81 | - Pagination (first page, last page, page out of range) |
| 82 | - Filtering and sorting combinations |
| 83 | |
| 84 | ### Step 3 — Generate Test Code |
| 85 | |
| 86 | Follow the structure below per framework. See `reference/framework-templates.md` for detailed templates. |
| 87 | |
| 88 | **General principles:** |
| 89 | - Each test should be atomic and independent (no shared mutable state) |
| 90 | - Use descriptive test names: `test_create_user_returns_201_with_valid_payload` |
| 91 | - Parameterize similar tests where appropriate (pytest `@pytest.mark.parametrize`, Jest `test.each`) |
| 92 | - Group tests by endpoint in a class or describe block |
| 93 | - Extract base URL, auth tokens, and reusable fixtures into a shared setup section |
| 94 | - Assert on: status code, response body fields, response headers (content-type), response time if relevant |
| 95 | |
| 96 | ### Step 4 — Output Structure |
| 97 | |
| 98 | Present output as: |
| 99 | 1. **Summary table** — endpoints covered, test count per category |
| 100 | 2. **Test file(s)** — complete, runnable code |
| 101 | 3. **Setup instructions** — how to install deps and run the suite |
| 102 | 4. **Coverage gaps** — any untestable scenarios due to missing spec info |
| 103 | |
| 104 | --- |
| 105 | |
| 106 | ## Output Examples by Framework |
| 107 | |
| 108 | ### pytest (Python) |
| 109 | |
| 110 | ```python |
| 111 | import pytest |
| 112 | import requests |
| 113 | |
| 114 | BASE_URL = "https://api.ex |