Software Development and Project Management

The values of temp and err can be chosen independently of each other. For the code 'if (temp > 80) { fan = HIGH; } else { fan = LOW; } if (err) { log(); }', what is the minimum number of test cases needed to achieve statement coverage (executing every statement at least once)?

  1. A2
  2. B3
  3. C4
Show answer and explanation

Answer: A. 2

There are three statements: fan = HIGH, fan = LOW and log(). Only one of fan = HIGH and fan = LOW is executed in a single run, so at least two runs are needed; for example, the two test cases (temp > 80, err true) and (temp ≤ 80, err false) execute all three statements. 3 is the number obtained by making one test case per statement, and 4 is the number of all combinations of true and false for the two conditions (all paths). Statement coverage is the weakest coverage criterion; for example, it can be achieved without ever taking the false side of the second if (the path that does nothing).

  • A. Correct. Two runs are needed to go through both the if and the else, and log() can be executed together with either of them.
  • B. This makes one test case per statement. One test case can execute several statements, so fewer are needed.
  • C. This is the number of all combinations of true and false (paths); statement coverage does not require that many.
Practice this topic Back to topic

Related calculators

Books on Software Development and Project Management Ad

As an Amazon Associate I earn from qualifying purchases.

More Software Development and Project Management questions

  1. The truth values of a, b and c can be chosen independently of each other. For the code 'if (a) { S1; } if (b) { S2; } if (c) { S3; }', what is the minimum number of test cases needed to achieve branch coverage (executing both the true and false outcomes of every decision at least once)?
  2. For the decision 'A and B' (A and B are conditions whose truth values can be set independently), two test cases were run: (A = true, B = false) and (A = false, B = true). Which statement about coverage criteria is correct?
  3. In bottom-up testing, what is built to stand in for a higher-level module that does not exist yet, so that it calls the lower-level module under test, passes it test data and receives the results?
  4. During testing, a reliability growth curve was plotted with the test time (or the number of test cases executed) on the horizontal axis and the cumulative number of defects found on the vertical axis. The curve is still rising, with no sign of saturating (leveling off). Which judgment is most appropriate?
  5. In the integration testing of firmware with 25 KLOC (25,000 lines), 30 defects were found. Based on the organization's past results, the guideline for defects found in this phase is 2 to 4 per KLOC. Which is the most appropriate evaluation of this result?