ExamGecko
Question list
Search
Search

Related questions











Question 196 - CTFL-2018 discussion

Report
Export

For the code fragment given below, which answer correctly represents minimum tests required for statement and branch coverage respectively?

A.
Statement Coverage = 2 Branch Coverage = 4
Answers
A.
Statement Coverage = 2 Branch Coverage = 4
B.
Statement Coverage = 1 Branch Coverage = 3
Answers
B.
Statement Coverage = 1 Branch Coverage = 3
C.
Statement Coverage = 2 Branch Coverage = 2
Answers
C.
Statement Coverage = 2 Branch Coverage = 2
D.
Statement Coverage = 1 Branch Coverage = 2
Answers
D.
Statement Coverage = 1 Branch Coverage = 2
Suggested answer: D

Explanation:

For the code fragment given below, one test case is required for statement coverage and two test cases are required for branch coverage. Statement coverage requires that every executable statement in the code is executed at least once. Branch coverage requires that every possible outcome of each decision point in the code is executed at least once. The following table shows how to achieve statement and branch coverage for the code fragment:

Test Case

Input

Output

Statement Coverage

Branch Coverage

1

x = 3

y = 9

S1, S2, S3

T1 = true

2

x = 5

y = 25

S1, S2

T1 = false

As shown in the table, test case 1 covers all three statements (S1, S2, S3) in the code fragment, achieving 100% statement coverage. Test case 2 covers only two statements (S1, S2) in the code fragment, but it exercises a different outcome of the decision point T1 (if x < 4), achieving 100% branch coverage.

asked 18/09/2024
Renats Fasulins
41 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first