API API Mocking and Stubbing 2 — Questions and Answers
Question 1: Which tool is commonly used to create a full fake REST API using only a JSON file as its data source?
- JUnit
- JSON Server (Correct answer)
- Selenium WebDriver
- Apache JMeter
Correct answer: JSON Server
JSON Server creates a complete fake REST API from a JSON file with zero backend code, making it ideal for rapid mock server setup during development.
Question 2: In WireMock, what is a 'stub mapping'?
- A mapping between JUnit test method names and their corresponding API endpoints
- A configuration that defines the request criteria to match and the response WireMock should return (Correct answer)
- A code generation tool that produces API client stubs from a WSDL definition
- A database schema used to persist mock responses across server restarts
Correct answer: A configuration that defines the request criteria to match and the response WireMock should return
A WireMock stub mapping specifies the request matching rules (URL pattern, HTTP method, headers, body) and the corresponding response to return when a request matches.
Question 3: What does 'request matching' mean in the context of API mock servers?
- Confirming that HTTP methods used by client and server are syntactically identical
- The process by which a mock server evaluates incoming request attributes to determine which configured response to return (Correct answer)
- Validating that all request headers conform to the API's published specification
- Comparing two separate API requests to detect differences in their structure
Correct answer: The process by which a mock server evaluates incoming request attributes to determine which configured response to return
Request matching is how mock servers evaluate attributes of an incoming request—such as URL, method, headers, and body—against configured rules to select the appropriate canned response.
Question 4: What is 'response templating' in API mocking tools such as WireMock?
- Automatically generating JSON schemas for API responses from OpenAPI documentation
- Dynamically constructing mock responses by injecting values extracted from the incoming request (Correct answer)
- Creating HTML-based templates used to render human-readable API documentation
- Auto-generating assertion code from observed API response payloads during test recording
Correct answer: Dynamically constructing mock responses by injecting values extracted from the incoming request
Response templating allows mock servers to build dynamic responses using data from the incoming request, such as path parameters, query strings, or request body fields.
Question 5: Which Postman feature enables you to simulate an API server and return predefined responses without a real backend?
- Postman Interceptor
- Postman Mock Server (Correct answer)
- Postman Monitor
- Postman Collection Runner
Correct answer: Postman Mock Server
Postman Mock Servers use saved response examples within a collection to create a hosted simulated API that returns predefined responses to incoming requests.
Question 6: What is the purpose of the 'record and replay' feature found in API mocking tools?
- Recording test execution videos for visual regression documentation
- Capturing real HTTP interactions with an actual API and replaying them as mock responses in subsequent tests (Correct answer)
- Recording API latency metrics over time and replaying load test scenarios
- Capturing raw network packets for later analysis in security testing workflows
Correct answer: Capturing real HTTP interactions with an actual API and replaying them as mock responses in subsequent tests
Record and replay captures live HTTP traffic from a real API and uses those recordings as mock responses, ensuring that mock data is realistic and matches actual API behavior.
Question 7: In Mockoon, what is a 'route'?
- A network path configuration between the client machine and the mock server host
- A defined endpoint with request matching rules and a configured response within the mock server (Correct answer)
- A URL redirect rule that forwards certain API requests to an external upstream service
- A sequence of API test steps executed in a specific order within a test collection
Correct answer: A defined endpoint with request matching rules and a configured response within the mock server
In Mockoon, a route is the fundamental building block of a mock server, representing a configured endpoint that matches specific incoming requests and returns a defined mock response.
Which tool is commonly used to create a full fake REST API using only a JSON file as its data source?