Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube - is Condition coverage actually the branch coverage?

SonarQube describes the "Condition" coverage like this:

On each line of code containing some boolean expressions, the condition coverage simply answers the following question: 'Has each boolean expression been evaluated both to true and false?'. This is the density of possible branches in flow control structures that have been followed during unit tests execution.

http://docs.codehaus.org/display/SONAR/Metric+definitions

Well but I suspect they mean "branch coverage":

if (A || B || C)

Testing A=true and B=true yields 100%, without the need of checking the last expression (C). Also just two branches are tested - true and false for the whole expression, not individual expressions. Is that right?

As far as I know, condition coverage should check all conditions in an expression.

like image 794
Pietross Avatar asked Nov 12 '14 08:11

Pietross


People also ask

Is condition coverage the same as branch coverage?

In branch coverage, all conditions must be executed at least once. On the other hand, in condition coverage, all possible outcomes of all conditions must be tested at least once.

Does basic condition coverage imply branch coverage?

No, it does not.

What is conditions to cover in SonarQube?

SonarQube describes the "Condition" coverage like this: On each line of code containing some boolean expressions, the condition coverage simply answers the following question: 'Has each boolean expression been evaluated both to true and false?' .

What is Branch condition coverage?

Branch coverage is a requirement that, for each branch in the program (e.g., if statements, loops), each branch have been executed at least once during testing. (It is sometimes also described as saying that each branch condition must have been true at least once and false at least once during testing.)


2 Answers

You can read the following thread of discussion: http://sonarqube.15.x6.nabble.com/I-can-t-understand-the-meaning-of-quot-condition-coverage-quot-in-SonarQube-tt5029339.html

like image 90
David RACODON - QA Consultant Avatar answered Oct 18 '22 02:10

David RACODON - QA Consultant


For me on SonarQube 5.6 condition coverage is really the same as path coverage as defined e.g. here: http://www.onjava.com/pub/a/onjava/2007/03/02/statement-branch-and-path-coverage-testing-in-java.html?page=2

For example, my test report points out that on an if-condition that checks two boolean flags, it insists that all 4 possible combinations have to be checked before 100% coverage is attained.

like image 26
Fritz Duchardt Avatar answered Oct 18 '22 03:10

Fritz Duchardt