Test execution reporting in Testing Fundamentals - Build an Automation Script
import os import pytest REPORT_PATH = 'test_report.txt' @pytest.fixture(scope='session', autouse=True) def generate_report(request): # Run tests and generate report after all tests yield # Simulate report generation for demonstration with open(REPORT_PATH, 'w') as f: f.write('Test Case: test_example_1 - PASS\n') f.write('Test Case: test_example_2 - FAIL\n') f.write('Total tests: 2\n') f.write('Passed: 1\n') f.write('Failed: 1\n') def test_example_1(): assert 1 + 1 == 2 def test_example_2(): assert 1 + 1 == 3 def test_report_file_exists(): assert os.path.exists(REPORT_PATH), f'Report file {REPORT_PATH} should exist' def test_report_contains_test_names(): with open(REPORT_PATH) as f: content = f.read() assert 'test_example_1' in content assert 'test_example_2' in content def test_report_contains_pass_fail_status(): with open(REPORT_PATH) as f: content = f.read() assert 'PASS' in content assert 'FAIL' in content def test_report_contains_summary(): with open(REPORT_PATH) as f: content = f.read() assert 'Total tests: 2' in content assert 'Passed: 1' in content assert 'Failed: 1' in content
This code uses pytest to run two simple test cases: one that passes and one that fails.
The generate_report fixture runs once per test session and after all tests finish, it creates a simple text report file test_report.txt with test names, pass/fail status, and summary counts.
Separate test functions then check that the report file exists and contains the expected information. This simulates verifying a test execution report.
Using fixtures and assertions keeps the code organized and clear. The report generation is simplified here for demonstration but shows the key idea of verifying test execution reporting.
Now add data-driven testing with 3 different inputs and verify the report includes all test runs
Practice
Solution
Step 1: Understand the role of test execution reports
Test execution reports summarize the results of running tests, showing which tests passed or failed.Step 2: Eliminate unrelated options
Writing test cases, designing software, and deploying are different activities not related to reporting test results.Final Answer:
To show which tests passed or failed -> Option CQuick Check:
Test execution report = pass/fail summary [OK]
- Confusing report with test design
- Thinking reports deploy software
- Assuming reports write tests
Solution
Step 1: Identify typical report contents
Test execution reports usually list test case names and whether they passed or failed.Step 2: Remove unrelated technical documents
Source code, UI sketches, and database diagrams are not part of test execution reports.Final Answer:
Test case names and their status -> Option AQuick Check:
Report = test names + status [OK]
- Including source code in reports
- Confusing reports with design documents
- Expecting diagrams in test reports
TestLogin: Passed
TestPayment: Failed
TestLogout: PassedHow many tests passed according to this report?
Solution
Step 1: Count tests marked as Passed
TestLogin and TestLogout are marked Passed, so 2 tests passed.Step 2: Confirm no other Passed tests
TestPayment is Failed, so it does not count.Final Answer:
2 -> Option BQuick Check:
Passed tests count = 2 [OK]
- Counting failed tests as passed
- Misreading the report lines
- Counting total tests instead of passed
TestA: Passed
TestB: Passed
TestC: Passed
TestD: PassedBut the tester says TestC actually failed. What is the most likely problem?
Solution
Step 1: Understand report and tester mismatch
If the report shows TestC passed but tester says it failed, the report is outdated or incorrect.Step 2: Evaluate other options
TestC was likely executed but result not updated; copying results is less common; all passing contradicts tester.Final Answer:
The report was not updated after the test run -> Option DQuick Check:
Report outdated = wrong pass shown [OK]
- Assuming test was not run
- Believing all tests passed
- Ignoring report update timing
Solution
Step 1: Identify useful report content
Listing all tests with their status helps the team see the full picture.Step 2: Emphasize failed tests and errors
Highlighting failures and showing error details helps developers fix issues quickly.Final Answer:
List all tests with status, highlight failed tests, and include error details -> Option AQuick Check:
Complete, clear report = best for fixing bugs [OK]
- Hiding failed or skipped tests
- Giving only totals without details
- Ignoring error messages
Ready to prove it?
Pass the test and this pattern moves unknown
