0
0
Testing Fundamentalstesting~10 mins

Request methods and status codes in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a web API correctly handles a GET request and returns the expected status code 200, indicating success.

Test Code - unittest
Testing Fundamentals
import requests
import unittest

class TestAPIRequestMethods(unittest.TestCase):
    def test_get_request_status_code(self):
        url = "https://jsonplaceholder.typicode.com/posts/1"
        response = requests.get(url)
        self.assertEqual(response.status_code, 200)

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest framework initialized, ready to run test_get_request_status_code-PASS
2Sends GET request to https://jsonplaceholder.typicode.com/posts/1HTTP request sent to the API endpoint-PASS
3Receives HTTP response from the serverResponse object contains status code and data-PASS
4Checks if response status code equals 200Response status code is 200 OKAssert response.status_code == 200PASS
5Test completes successfullyTest framework reports test passed-PASS
Failure Scenario
Failing Condition: The API returns a status code other than 200 (e.g., 404 or 500)
Execution Trace Quiz - 3 Questions
Test your understanding
What HTTP method is used in this test?
APOST
BPUT
CGET
DDELETE
Key Result
Always verify that the API returns the expected status code for the request method used. This confirms the API behaves correctly for that operation.