0
0
Testing Fundamentalstesting~20 mins

Statement coverage in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Statement Coverage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Statement Coverage

Which of the following best describes statement coverage in software testing?

AIt measures the percentage of executable statements in the code that have been executed by the test cases.
BIt measures the percentage of decision outcomes (true/false) tested in the code.
CIt measures the number of test cases executed during testing.
DIt measures the time taken to execute all test cases.
Attempts:
2 left
💡 Hint

Think about what part of the code is actually run during testing.

Predict Output
intermediate
2:00remaining
Calculate Statement Coverage Percentage

Given the following code and test cases, what is the statement coverage percentage?

def check_number(x):
    if x > 0:
        print("Positive")
    else:
        print("Non-positive")

# Test cases:
check_number(5)
A25%
B50%
C100%
D75%
Attempts:
2 left
💡 Hint

Count how many lines run when check_number(5) is called.

assertion
advanced
2:00remaining
Assertion for Full Statement Coverage

Which assertion correctly verifies that a test suite achieves 100% statement coverage for the following function?

def is_even(n):
    if n % 2 == 0:
        return True
    else:
        return False
Aassert statement_coverage(is_even_tests) == 0
Bassert statement_coverage(is_even_tests) < 100
Cassert statement_coverage(is_even_tests) >= 50
Dassert statement_coverage(is_even_tests) == 100
Attempts:
2 left
💡 Hint

Full coverage means all lines run at least once.

🔧 Debug
advanced
2:00remaining
Debugging Statement Coverage Measurement

Consider this test code measuring statement coverage. It reports 80% coverage, but the tester expects 100%. What is the likely cause?

def foo(x):
    if x > 0:
        print("Positive")
    else:
        print("Zero or Negative")

# Test cases
foo(1)
# Coverage measured here
AThe function foo has a syntax error causing incomplete coverage.
BThe print statements cause the coverage tool to fail.
CThe test cases do not cover the else branch, so some statements are not executed.
DThe coverage tool only measures function calls, not statements.
Attempts:
2 left
💡 Hint

Think about which lines run when foo(1) is called.

framework
expert
2:30remaining
Integrating Statement Coverage in Automated Testing

Which option correctly describes how to integrate statement coverage measurement into an automated Python test suite using pytest and coverage.py?

ARun tests with <code>coverage run -m pytest</code> then generate report with <code>coverage report</code>.
BAdd <code>assert coverage == 100</code> inside each test function manually.
CRun tests with <code>pytest --coverage</code> without installing any extra tools.
DUse <code>pytest-cov</code> but coverage reports are generated automatically without any commands.
Attempts:
2 left
💡 Hint

Think about the standard commands to run coverage with pytest.