Test Overview
This test checks if the application responds within an acceptable time limit when loading the homepage. It verifies that the page load time is under 2 seconds to identify any performance bottlenecks.
This test checks if the application responds within an acceptable time limit when loading the homepage. It verifies that the page load time is under 2 seconds to identify any performance bottlenecks.
import time import unittest class PerformanceTest(unittest.TestCase): def test_homepage_load_time(self): start_time = time.time() # Simulate loading homepage load_homepage() # Assume this function loads the homepage end_time = time.time() load_duration = end_time - start_time self.assertLess(load_duration, 2.0, f"Homepage load took too long: {load_duration} seconds") def load_homepage(): # Simulated delay representing page load time.sleep(1.5) # 1.5 seconds load time if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, ready to execute test_homepage_load_time | - | PASS |
| 2 | Records start time | Current time noted before homepage load | - | PASS |
| 3 | Calls load_homepage function to simulate page loading | Simulated homepage loading with 1.5 seconds delay | - | PASS |
| 4 | Records end time after homepage load | Current time noted after homepage load | - | PASS |
| 5 | Calculates load duration and asserts it is less than 2 seconds | Load duration calculated as approximately 1.5 seconds | Assert load_duration < 2.0 seconds | PASS |
| 6 | Test ends with PASS | Homepage load time is within acceptable limit | - | PASS |