Test Overview
This test compares the behavior of a mock server and a stub in Postman. It verifies that the mock server returns the predefined response and the stub simulates a simple response for a dependent API call.
This test compares the behavior of a mock server and a stub in Postman. It verifies that the mock server returns the predefined response and the stub simulates a simple response for a dependent API call.
import requests # URL of the Postman mock server mock_url = "https://abc123.mock.pstmn.io/resource" # URL of the stub endpoint (simulated with a simple local server or mock) stub_url = "https://stub-server.local/api/v1/dependency" # Test the mock server response mock_response = requests.get(mock_url) assert mock_response.status_code == 200, f"Expected 200 but got {mock_response.status_code}" assert mock_response.json().get('message') == 'Mock response', "Mock response message mismatch" # Test the stub response stub_response = requests.get(stub_url) assert stub_response.status_code == 200, f"Expected 200 but got {stub_response.status_code}" assert stub_response.text == 'Stub response', "Stub response content mismatch"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment ready with mock server and stub endpoint URLs configured | - | PASS |
| 2 | Send GET request to Postman mock server URL | Mock server is running and ready to respond | Check if status code is 200 | PASS |
| 3 | Verify mock server response JSON contains 'message' with value 'Mock response' | Response JSON received from mock server | Assert response JSON 'message' == 'Mock response' | PASS |
| 4 | Send GET request to stub endpoint URL | Stub endpoint is running and ready to respond | Check if status code is 200 | PASS |
| 5 | Verify stub response text equals 'Stub response' | Response text received from stub endpoint | Assert response text == 'Stub response' | PASS |
| 6 | Test ends successfully with all assertions passed | Both mock and stub responses verified | - | PASS |