0
0
Testing Fundamentalstesting~8 mins

Request methods and status codes in Testing Fundamentals - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Request methods and status codes
Folder Structure
api-testing-framework/
├── tests/
│   ├── test_get_requests.py
│   ├── test_post_requests.py
│   ├── test_put_requests.py
│   ├── test_delete_requests.py
│   ├── test_patch_requests.py
│   └── test_status_codes.py
├── utils/
│   ├── api_client.py
│   └── helpers.py
├── config/
│   ├── environments.yaml
│   └── credentials.yaml
├── reports/
│   └── latest_report.html
├── conftest.py
└── pytest.ini
  
Test Framework Layers
  • API Client Layer: Handles sending HTTP requests (GET, POST, PUT, PATCH, DELETE) and receiving responses.
  • Test Layer: Contains test cases that verify request methods and validate status codes.
  • Utilities Layer: Helper functions for common tasks like building URLs, parsing responses, and logging.
  • Configuration Layer: Stores environment URLs, credentials, and other settings to run tests in different setups.
  • Reporting Layer: Generates test execution reports and integrates with CI/CD pipelines.
Configuration Patterns
  • Environment Files: Use YAML or JSON files (e.g., environments.yaml) to define base URLs for dev, staging, and production.
  • Credentials Management: Store API keys or tokens securely in separate config files or environment variables.
  • Parameterization: Use fixtures or config parsers to switch environments and credentials without changing test code.
  • Browser/Client Settings: For API testing, configure headers, timeouts, and retries in the API client layer.
Test Reporting and CI/CD Integration
  • Use pytest-html or Allure to generate readable HTML reports showing passed and failed tests with details.
  • Integrate test runs into CI/CD pipelines (e.g., GitHub Actions, Jenkins) to run tests automatically on code changes.
  • Configure reports to include request and response details for failed tests to help debugging.
  • Set up notifications (email, Slack) to alert the team when tests fail.
Best Practices
  • Use Clear Naming: Name tests by HTTP method and expected status code (e.g., test_get_returns_200).
  • Isolate Tests: Each test should focus on one request method and one expected status code to keep tests simple.
  • Validate Status Codes: Always assert the HTTP status code matches the expected result (e.g., 200 OK, 404 Not Found).
  • Use Reusable API Client: Centralize request sending logic to avoid duplication and ease maintenance.
  • Handle Negative Cases: Test error status codes like 400, 401, 403, 404 to ensure API handles bad requests properly.
Self Check

Where in this folder structure would you add a new test for verifying the PATCH request method?

Key Result
Organize API tests by separating request methods, status code validations, utilities, and configurations for clear, maintainable testing.