Formula:
Statement Coverage (%) = (Number of Executed Statements / Total Executable Statements) × 100
2. Objective:
2. Decision Logic Coverage:
if
, else
, switch
) are tested.if-else
a statement, achieving 100% statement coverage may test only one path (e.g., if
), leaving the else
untested.Consider the following code snippet:
if (x > 0):
print("Positive number")
else:
print("Non-positive number")
print("End of program")
x = 5
Positive number
, End of program
if
statement and the final print statement.x = -3
Non-positive number
, End of program
else
statement and the final print statement.100% statement coverage requires both test cases since all lines of code are executed at least once.
Takeaway: While 100% statement coverage is a useful goal, testers should also focus on other coverage types (e.g., branch coverage) to ensure the entire decision logic is thoroughly tested.
a) Ensuring all branches in the code are tested
b) Ensuring all lines of code are executed at least once
c) Ensuring all decision outcomes are tested
d) Ensuring all test cases are valid
Answer: b) Ensuring all lines of code are executed at least once
a) It guarantees the absence of defects in the software
b) It ensures all branches in decision-making are tested
c) It ensures every executable statement in the code is tested at least once
d) It ensures all combinations of inputs are tested
Answer: c) It ensures every executable statement in the code is tested at least once
a) (Number of executed branches / Total branches) × 100
b) (Number of executed statements / Total executable statements) × 100
c) (Number of executed decisions / Total decisions) × 100
d) (Number of test cases / Total test cases) × 100
Answer: b) (Number of executed statements / Total executable statements) × 100
a) Syntax errors in unexecuted code
b) Defects in executed statements
c) Dead code that is unreachable
d) Data-dependent errors, such as division by zero
Answer: d) Data-dependent errors, such as division by zero
a) All paths in the program
b) All statements in the program
c) All conditions in the program
d) All branches in the program
Answer: b) All statements in the program
a) It is impossible to achieve in most real-world applications
b) It does not test decision logic or all possible outcomes
c) It requires testing every possible input value
d) It only applies to non-executable statements
Answer: b) It does not test decision logic or all possible outcomes
if x > 0:
print("Positive")
else:
print("Non-positive")
print("Done")
a) Test case: x = 1
b) Test case: x = -1
c) Test case: x = 0
d) Test cases: x = 1 and x = -1
Answer: d) Test cases: x = 1 and x = -1
a) Branch coverage
b) Condition coverage
c) Decision coverage
d) None of the above
Answer: d) None of the above