API API Test Automation 1 — Questions and Answers
Question 1: Which Python library is commonly used for writing automated REST API tests?
- Selenium
- Requests + PyTest (Correct answer)
- Playwright
- Beautiful Soup
Correct answer: Requests + PyTest
The `requests` library handles HTTP calls while `pytest` provides the test framework, making them the standard Python combo for API test automation.
Question 2: What is the purpose of a test fixture in API automation frameworks?
- Generate API documentation
- Set up and tear down test preconditions consistently (Correct answer)
- Monitor API response times
- Define API endpoints
Correct answer: Set up and tear down test preconditions consistently
Fixtures prepare the environment before tests run (setup) and clean up after they finish (teardown), ensuring consistent, isolated test conditions.
Question 3: What does 'data-driven testing' mean in the context of API automation?
- Testing APIs that serve big data
- Running the same test logic with multiple sets of input data (Correct answer)
- Generating test data from the API response
- Storing test results in a database
Correct answer: Running the same test logic with multiple sets of input data
Data-driven testing separates test logic from data, running the same test scenario with different inputs from an external source like CSV or JSON.
Question 4: Which concept in API test automation ensures tests do not depend on each other or share state?
- Parallel execution
- Test isolation (Correct answer)
- Mocking
- Continuous integration
Correct answer: Test isolation
Test isolation ensures each test runs independently with its own setup and teardown, preventing one test's state from affecting another's result.
Question 5: What is a mock server used for in API test automation?
- Simulating an API dependency without calling the real service (Correct answer)
- Running performance tests
- Generating API documentation
- Scanning for vulnerabilities
Correct answer: Simulating an API dependency without calling the real service
A mock server simulates the behavior of a real API dependency, allowing tests to run without relying on external services that may be unavailable or slow.
Question 6: Which CI/CD integration practice automatically runs API test suites on every code commit?
- Blue-green deployment
- Continuous testing in the pipeline (Correct answer)
- Feature flagging
- Canary releasing
Correct answer: Continuous testing in the pipeline
Integrating API tests into the CI/CD pipeline ensures tests run automatically on every commit, catching regressions before code reaches production.
Which Python library is commonly used for writing automated REST API tests?