Test Overview
This test simulates running a performance test on a web application and verifies that the performance report is generated correctly with key metrics like response time and throughput.
This test simulates running a performance test on a web application and verifies that the performance report is generated correctly with key metrics like response time and throughput.
import unittest class PerformanceReportTest(unittest.TestCase): def test_performance_report_generation(self): # Simulate performance test results performance_data = { 'average_response_time_ms': 120, 'max_response_time_ms': 300, 'throughput_rps': 50, 'error_rate_percent': 0.5 } # Generate report string report = (f"Average Response Time: {performance_data['average_response_time_ms']} ms\n" f"Max Response Time: {performance_data['max_response_time_ms']} ms\n" f"Throughput: {performance_data['throughput_rps']} requests/sec\n" f"Error Rate: {performance_data['error_rate_percent']}%") # Verify report contains all key metrics self.assertIn('Average Response Time', report) self.assertIn('Max Response Time', report) self.assertIn('Throughput', report) self.assertIn('Error Rate', report) # Verify values are correct self.assertIn('120 ms', report) self.assertIn('300 ms', report) self.assertIn('50 requests/sec', report) self.assertIn('0.5%', report) if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initializes the test case | - | PASS |
| 2 | Simulate performance test results with average response time 120 ms, max 300 ms, throughput 50 rps, error rate 0.5% | Performance data dictionary created in memory | - | PASS |
| 3 | Generate performance report string with all metrics | Report string contains all performance metrics formatted | - | PASS |
| 4 | Check report contains 'Average Response Time' | Report string is available | assertIn('Average Response Time', report) | PASS |
| 5 | Check report contains 'Max Response Time' | Report string is available | assertIn('Max Response Time', report) | PASS |
| 6 | Check report contains 'Throughput' | Report string is available | assertIn('Throughput', report) | PASS |
| 7 | Check report contains 'Error Rate' | Report string is available | assertIn('Error Rate', report) | PASS |
| 8 | Verify '120 ms' value is in report | Report string is available | assertIn('120 ms', report) | PASS |
| 9 | Verify '300 ms' value is in report | Report string is available | assertIn('300 ms', report) | PASS |
| 10 | Verify '50 requests/sec' value is in report | Report string is available | assertIn('50 requests/sec', report) | PASS |
| 11 | Verify '0.5%' value is in report | Report string is available | assertIn('0.5%', report) | PASS |
| 12 | Test ends successfully | All assertions passed, test completes | - | PASS |