Verify GET request to retrieve user data using Postman
Preconditions (2)
✅ Expected Result: Response status code is 200 OK and response body contains user data with id 1
import unittest import requests class TestGetUserAPI(unittest.TestCase): def test_get_user(self): url = "https://jsonplaceholder.typicode.com/users/1" try: response = requests.get(url, timeout=5) self.assertEqual(response.status_code, 200, "Status code is not 200") data = response.json() self.assertEqual(data.get('id'), 1, "User ID is not 1") except requests.RequestException as e: self.fail(f"Request failed: {e}") if __name__ == '__main__': unittest.main()
This test uses Python's unittest framework and requests library to automate the manual test case.
We send a GET request to the API endpoint and check the status code is 200, which means success.
Then we parse the JSON response and verify the id field equals 1, matching the expected user.
We use a try-except block to catch any network errors and fail the test with a clear message.
This keeps the test simple, readable, and reliable.
Now add data-driven testing with 3 different user IDs (1, 2, 3) to verify their data
given().when().get("https://api.example.com/users/1").then().statusCode(200);curl -X GET https://api.example.com/data -d '{"id":5}'Pass the test and this pattern moves unknown