0
0
Testing Fundamentalstesting~10 mins

REST API testing basics in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to a REST API endpoint and verifies that the response status code is 200, indicating success.

Test Code - PyTest
Testing Fundamentals
import requests

def test_get_api_status():
    url = "https://jsonplaceholder.typicode.com/posts/1"
    response = requests.get(url)
    assert response.status_code == 200
    data = response.json()
    assert data["id"] == 1
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment ready, no network calls made yet-PASS
2Send GET request to https://jsonplaceholder.typicode.com/posts/1Request sent to the API server-PASS
3Receive response from APIResponse received with status code 200 and JSON bodyCheck if response.status_code == 200PASS
4Parse JSON response bodyResponse body parsed into a dictionaryCheck if data["id"] == 1PASS
5Test ends successfullyAll assertions passed, test completed-PASS
Failure Scenario
Failing Condition: API returns a status code other than 200 or the JSON response does not contain the expected id
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first after sending the GET request?
AThat the response status code is 200
BThat the response body is empty
CThat the request method is POST
DThat the server is offline
Key Result
Always verify both the HTTP status code and the response content to ensure the API behaves as expected.