0
0
Testing Fundamentalstesting~10 mins

Performance testing tools overview in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates a simple performance test scenario using a tool like Apache JMeter. It verifies that the tool can send a request to a web server and measure the response time correctly.

Test Code - unittest
Testing Fundamentals
import unittest
import time
import requests

class PerformanceTest(unittest.TestCase):
    def test_response_time_under_limit(self):
        url = "https://example.com"
        max_response_time = 0.5  # seconds
        start_time = time.time()
        response = requests.get(url)
        end_time = time.time()
        response_time = end_time - start_time
        self.assertEqual(response.status_code, 200)
        self.assertLessEqual(response_time, max_response_time, f"Response time {response_time} exceeded limit")

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initializes the PerformanceTest class-PASS
2Sends HTTP GET request to https://example.comNetwork connection established, request sent-PASS
3Receives HTTP responseResponse received with status code 200 and response bodyCheck if response.status_code == 200PASS
4Measures response timeResponse time calculated as end_time - start_timeCheck if response_time <= 0.5 secondsPASS
5Test ends with all assertions passedTest report shows success-PASS
Failure Scenario
Failing Condition: Response time exceeds 0.5 seconds or status code is not 200
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the HTTP response?
AThe response body contains specific text
BThe response status code is 200
CThe server uses HTTPS
DThe request method is POST
Key Result
Always measure and assert response times in performance tests to ensure your application meets speed requirements.