Bird
Raised Fist0
Testing Fundamentalstesting~15 mins

Test progress reporting in Testing Fundamentals - Build an Automation Script

Choose your learning style10 modes available
Verify test progress reporting during test suite execution
Preconditions (2)
Step 1: Run the test suite
Step 2: Observe the progress output during test execution
Step 3: Verify that progress updates are shown after each test case completes
Step 4: Verify that the final progress shows 100% completion
โœ… Expected Result: Progress updates are displayed after each test case, showing incremental completion percentage, and final output shows 100% completion.
Automation Requirements - pytest
Assertions Needed:
Verify progress output contains incremental progress updates
Verify final progress output shows 100% completion
Best Practices:
Use pytest hooks to capture progress output
Use assertions to check output correctness
Keep tests independent and clear
Automated Solution
Testing Fundamentals
import pytest
import io
import sys

def test_case_1():
    assert True

def test_case_2():
    assert True

def test_case_3():
    assert True

def test_case_4():
    assert True

def test_case_5():
    assert True

class ProgressReporter:
    def __init__(self):
        self.progress_updates = []

    def pytest_runtest_logreport(self, report):
        if report.when == 'call' and report.passed:
            self.progress_updates.append(f"Test {report.nodeid} passed")

@pytest.fixture
def progress_reporter():
    reporter = ProgressReporter()
    return reporter


def test_progress_reporting(progress_reporter, capsys):
    # Run all test cases manually to simulate progress
    test_functions = [test_case_1, test_case_2, test_case_3, test_case_4, test_case_5]
    total = len(test_functions)
    for i, test_func in enumerate(test_functions, 1):
        test_func()
        progress = (i / total) * 100
        print(f"Progress: {progress:.0f}%")

    captured = capsys.readouterr()
    lines = captured.out.strip().split('\n')

    # Check that progress increments correctly
    expected_progress = [f"Progress: {int((i/total)*100)}%" for i in range(1, total+1)]
    assert lines == expected_progress, f"Expected progress lines {expected_progress}, got {lines}"

    # Check final progress is 100%
    assert lines[-1] == "Progress: 100%"

This test script defines 5 simple test cases that always pass.

The test_progress_reporting function runs each test case one by one, printing the progress percentage after each test completes.

We capture the printed output using capsys fixture to verify the progress messages.

Assertions check that the progress messages increment correctly and that the final progress is 100%.

This simulates progress reporting during a test suite run.

Common Mistakes - 3 Pitfalls
{'mistake': 'Not capturing printed output for progress verification', 'why_bad': 'Without capturing output, you cannot verify progress messages programmatically.', 'correct_approach': "Use pytest's capsys fixture to capture and assert printed progress output."}
Running all tests at once without intermediate progress updates
Hardcoding progress percentages without calculation
Bonus Challenge

Now add data-driven testing with 3 different inputs and report progress after each input test

Show Hint

Practice

(1/5)
1. What does test progress reporting mainly show during software testing?
easy
A. How many tests have been completed and how many are left
B. The total number of bugs found in the software
C. The time taken to write each test case
D. The number of developers working on the project

Solution

  1. Step 1: Understand the purpose of test progress reporting

    Test progress reporting is designed to show the current status of testing, specifically how many tests are done and how many remain.
  2. Step 2: Compare options with the definition

    Only How many tests have been completed and how many are left correctly describes this purpose. Other options describe different metrics unrelated to progress reporting.
  3. Final Answer:

    How many tests have been completed and how many are left -> Option A
  4. Quick Check:

    Progress reporting = tests done vs remaining [OK]
Hint: Focus on tests done and left to find progress [OK]
Common Mistakes:
  • Confusing bug count with progress
  • Thinking progress shows developer count
  • Mixing test writing time with progress
2. Which of the following is the correct way to represent test progress as a percentage?
easy
A. (Total tests / Number of tests completed) * 100
B. (Number of tests completed / Total tests) * 100
C. (Number of tests remaining / Number of tests completed) * 100
D. (Number of tests completed - Number of tests remaining) * 100

Solution

  1. Step 1: Recall the formula for percentage progress

    Progress percentage is calculated by dividing completed tests by total tests, then multiplying by 100.
  2. Step 2: Evaluate each option

    (Number of tests completed / Total tests) * 100 matches the correct formula. Options B, C, and D use incorrect divisions or operations.
  3. Final Answer:

    (Number of tests completed / Total tests) * 100 -> Option B
  4. Quick Check:

    Progress % = completed รท total x 100 [OK]
Hint: Divide completed by total, then multiply by 100 [OK]
Common Mistakes:
  • Reversing numerator and denominator
  • Using subtraction instead of division
  • Multiplying before dividing
3. Consider this code snippet updating test progress:
total_tests = 50
completed_tests = 20
progress = (completed_tests / total_tests) * 100
print(f"Progress: {progress}%")
What will be the printed output?
medium
A. Progress: 25.0%
B. Progress: 20.0%
C. Progress: 50.0%
D. Progress: 40.0%

Solution

  1. Step 1: Calculate the progress value

    progress = (20 / 50) * 100 = 0.4 * 100 = 40.0
  2. Step 2: Check the printed output

    The print statement outputs "Progress: 40.0%" exactly.
  3. Final Answer:

    Progress: 40.0% -> Option D
  4. Quick Check:

    20 รท 50 x 100 = 40.0 [OK]
Hint: Divide completed by total, multiply by 100 for percent [OK]
Common Mistakes:
  • Misreading completed and total values
  • Confusing 20/50 as 25%
  • Ignoring multiplication by 100
4. A tester wrote this code to show test progress:
total_tests = 100
completed_tests = 30
progress = completed_tests / total_tests * 100
print("Progress: " + progress + "%")
What is the error in this code?
medium
A. Division by zero error
B. Incorrect formula for progress
C. Cannot concatenate string and float directly
D. Missing parentheses in print statement

Solution

  1. Step 1: Identify the data types in the print statement

    progress is a float, and the code tries to concatenate it directly with strings using +.
  2. Step 2: Understand Python string concatenation rules

    Python cannot concatenate string and float directly; progress must be converted to string first.
  3. Final Answer:

    Cannot concatenate string and float directly -> Option C
  4. Quick Check:

    String + float needs conversion [OK]
Hint: Convert numbers to string before concatenation [OK]
Common Mistakes:
  • Assuming division by zero
  • Thinking formula is wrong
  • Ignoring type errors in print
5. You want to create a test progress report that updates after each test and shows both fraction and percentage. Which approach is best?
hard
A. After each test, print: "Completed X/Y tests (Z%)" where Z = (X/Y)*100
B. Print total tests once, then print completed tests separately without percentage
C. Only print percentage after all tests finish
D. Print completed tests count only, no total or percentage

Solution

  1. Step 1: Understand the goal of progress reporting

    It should show how many tests are done, total tests, and progress percentage updated continuously.
  2. Step 2: Evaluate each option for completeness and clarity

    After each test, print: "Completed X/Y tests (Z%)" where Z = (X/Y)*100 shows fraction and percentage after each test, which is clear and informative. Other options miss key info or delay updates.
  3. Final Answer:

    After each test, print: "Completed X/Y tests (Z%)" where Z = (X/Y)*100 -> Option A
  4. Quick Check:

    Show fraction and percent continuously [OK]
Hint: Show fraction and percent after each test for clarity [OK]
Common Mistakes:
  • Not updating progress continuously
  • Omitting total tests count
  • Showing only percentage or only count
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard