0
0
Testing Fundamentalstesting~10 mins

Performance testing basics in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates multiple users accessing a website at the same time to check if the website stays fast and stable. It verifies that the website responds within an acceptable time under load.

Test Code - Python threading with requests
Testing Fundamentals
import time
from threading import Thread
import requests

responses = []

# Function to simulate a user sending a request
def simulate_user(url):
    start = time.time()
    response = requests.get(url)
    end = time.time()
    responses.append((response.status_code, end - start))

# URL to test
url = 'https://example.com'

# Number of simulated users
num_users = 5

threads = []
for _ in range(num_users):
    thread = Thread(target=simulate_user, args=(url,))
    threads.append(thread)
    thread.start()

for thread in threads:
    thread.join()

# Check all responses
for status, duration in responses:
    assert status == 200, f"Expected status 200 but got {status}"
    assert duration < 2, f"Response took too long: {duration} seconds"
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest script is ready to run-PASS
2Starts 5 threads to simulate 5 users sending requests to https://example.com5 threads running, each sending HTTP GET request-PASS
3Each thread sends a GET request and records response status and time takenResponses collected with status codes and durations-PASS
4Main thread waits for all user threads to finishAll threads completed-PASS
5Check each response status is 200 and response time is less than 2 secondsAll responses verifiedAssert status == 200 and duration < 2 seconds for each responsePASS
6Test ends with all assertions passedTest completed successfully-PASS
Failure Scenario
Failing Condition: One or more responses have status code not equal to 200 or response time exceeds 2 seconds
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test simulate in performance testing?
AMultiple users accessing the website at the same time
BA single user clicking buttons repeatedly
CChecking spelling errors on the website
DVerifying the website layout on mobile devices
Key Result
Performance tests should simulate real user load and verify both response correctness and response time limits to ensure the system can handle expected traffic.