Skip to content
All notes
27API TestingAPI TestingTest Cases

What are common API test cases you would write?

1. Functional Test Cases

  • Verify API returns correct response for valid request
  • Test all HTTP methods (GET, POST, PUT, DELETE, PATCH)
  • Validate response status codes
  • Verify response body structure and data
  • Test with different input combinations
  • Validate response headers

2. Negative Test Cases

  • Test with invalid API endpoint
  • Test with invalid HTTP method
  • Test with missing required parameters
  • Test with invalid data types
  • Test with out-of-range values
  • Test with special characters and SQL injection
  • Test with empty/null values

3. Authentication & Authorization

  • Test without authentication token
  • Test with invalid/expired token
  • Test with valid token
  • Test role-based access control
  • Test token refresh mechanism

4. Performance Test Cases

  • Verify response time is within acceptable limits
  • Test API under load (concurrent users)
  • Test with large payload
  • Verify API handles timeout scenarios

5. Data Validation

  • Validate JSON/XML schema
  • Verify data types in response
  • Check for required vs optional fields
  • Validate date formats
  • Verify enum values

Example Test Case

Test Case: Create User API

  • Endpoint: POST /api/users
  • Headers: Content-Type: application/json, Authorization: Bearer token
  • Body: {“name”: “John”, “email”: “john@test.com”}
  • Expected: Status 201, Response contains user ID
  • Validation: User created in database