Automation Testing API Test Automation 2 — Questions and Answers
Question 1: Which Java library is commonly used for REST API test automation with fluent syntax?
- REST Assured (Correct answer)
- OkHttp
- Apache HttpClient
- Retrofit
Correct answer: REST Assured
REST Assured provides a domain-specific language for writing readable, fluent API tests in Java with built-in assertion and validation support.
Question 2: What does mocking an API dependency mean in test automation?
- Simulating the API's behavior with a fake server so tests run independently of the real service (Correct answer)
- Testing an API that has no documentation
- Running tests against a staging server
- Generating API load
Correct answer: Simulating the API's behavior with a fake server so tests run independently of the real service
API mocking creates a simulated server that returns predefined responses, allowing tests to run without depending on external services.
Question 3: What HTTP method should be used for an API call that only retrieves data without side effects?
- GET (Correct answer)
- POST
- PUT
- PATCH
Correct answer: GET
GET is the idempotent, safe HTTP method for retrieving resources without modifying server state.
Question 4: What is contract testing in API test automation?
- Verifying that an API provider and consumer agree on the API structure via a shared contract (Correct answer)
- Testing API SLA compliance
- Testing API rate limits
- Validating API documentation completeness
Correct answer: Verifying that an API provider and consumer agree on the API structure via a shared contract
Contract testing (e.g., with Pact) ensures the API consumer and provider independently verify they honor the agreed interface contract.
Question 5: Which HTTP status code indicates that the requested API resource was not found?
- 404 Not Found (Correct answer)
- 400 Bad Request
- 403 Forbidden
- 500 Internal Server Error
Correct answer: 404 Not Found
HTTP 404 Not Found indicates the server cannot locate the requested resource at the given URI.
Question 6: What is the difference between a query parameter and a path parameter in a REST API?
- Path parameters are part of the URL path; query parameters appear after '?' as key-value pairs (Correct answer)
- They are identical in function
- Query parameters are required; path parameters are optional
- Path parameters use POST; query parameters use GET
Correct answer: Path parameters are part of the URL path; query parameters appear after '?' as key-value pairs
Path parameters (e.g., /users/{id}) identify a specific resource, while query parameters (e.g., ?sort=asc) filter or modify the request.
Which Java library is commonly used for REST API test automation with fluent syntax?