• Software Testing Dictionary
  • Home

Condition Coverage Testing



Software testing is mainly of two types white box and black box testing. While performing the white box testing, internal code, data structures, algorithms, logic, flow and other interiors of the software are verified. Condition coverage testing is one of the concepts under the white box testing technique. It involves validating every conditional expression in the program source code for all possible results of the conditions described in the conditional expressions.

What is Software Condition Coverage Testing?

The software condition coverage testing is a part of the white box testing. It is used by the developers to design white box test cases. It is primarily focused on covering all the conditions in the program source code. It is also referred to as predicate coverage testing.

In the software condition coverage testing every Boolean expression described in the conditions expression is evaluated to both true and false outcomes. As a result, it ensures that both the branches in a decision statement are tested. In case, a decision statement comprises various conditions namely OR, and AND, the condition coverage testing confirms that all the various combinations of the conditions are included in the test cases.

Formula to Calculate the Software Condition Coverage Percentage

The software condition coverage can be calculated by dividing the total count of conditions executed with the total count of conditions in the source code, and then multiplied by hundred.

Condition Coverage = (Total count of conditions executed / Total count of conditions in the source code) * 100

Why is Software Condition Coverage Testing Required?

The software condition coverage testing is required to ensure that the program source code is working properly, and is able to satisfy the given requirements. It is observed that the traditional testing methodologies sometimes miss particular paths in the code, thereby some of the critical defects remain undetected. The software condition coverage testing takes care of these situations by methodically verifying all the conditions inside the decision points. Thus it improves the overall quality, and performance of the software.

How is Software Condition Coverage Testing Performed?

The software condition coverage testing are performed by following the steps listed below −

Step 1 − Determine the decision points or conditional statements in the program source code like the if, else if, if, switch etc.

Step 2 − Every decision point may consist of more than one condition. These conditions are evaluated, and split into simpler modules to have an exhaustive testing.

Step 3 − Design test cases to include every possible result of all the conditions namely true, and false. It helps to cover every branch of code at the time of testing.

Step 4 − Execute the white box test cases, and evaluate the results. A coverage report is generated to measure the extent of verification of the conditions. It also describes the validated, and invalidated conditions, thereby it gives an idea if more fine tuning of the test cases are needed.

Advantages of Software Condition Coverage Testing

The advantages of the software condition coverage testing are listed below −

  • The software condition coverage testing guarantees that all the conditions in the code are checked at least once.
  • The software condition coverage testing detects defects from the early stages of the software development life cycle(SDLC).
  • The condition coverage testing improves the quality, maintainability, and reliability of the software.
  • The software condition coverage testing helps in faster troubleshooting of errors in the code.
  • The condition coverage testing gives higher confidence, and trust on the code developed for the software.

Example

Let us take an example of the below code snippet to determine the count of the condition coverage.

Input X, Y, Z, and W 
IF (X == 0 || Y == 0) 
   THEN PRINT 100
   ELSE IF (Z == 0 && W == 0) 
      THEN PRINT 200
   END IF
END

Let us now calculate the condition coverage with the first test case, with the inputs X = 0, Y = 0, Z = 0, W = 0. With these values, the first condition of the OR operator with the expression X == 0, holds true. Since the result of the left side of the OR is already true, so the right side of the expression, Y == 0 of it, will be skipped from evaluation.

So, the condition Y == 0 remained unchecked. Then, the statement 3 will be executed resulting in printing 100 and the condition IF (Z == 0 && W == 0) in the ELSE part(at the line 4) will not be executed. Hence, out of a total four conditions, only one of them got executed. The total condition coverage as per formula:

Condition Coverage = (Total count of conditions executed / Total count of conditions in the source code) * 100

Condition Coverage = (1 / 4) * 100 = 25 %.

Let us now calculate the condition coverage with the second test case, with the inputs X = 1, Y = 0, Z = 0, W = 0. With these values, the first condition having the OR operator with the expression X == 1, holds false. As the result of the left side of the OR is false, so the right side expression Y == 0 of it, will be evaluated. So this time, the condition Y == 0 is checked. Then, the statement 3 will be executed resulting in printing 100 and the condition IF (Z == 0 && W == 0) in the ELSE part(at the line 4) will remain unchecked. Hence, out of a total four conditions, two of them got executed. The total condition coverage as per formula

Condition Coverage = (Total count of conditions executed / Total count of conditions in the source code) * 100

Condition Coverage = (2 / 4) * 100 = 50 %.

Let us now calculate the condition coverage with the third test case, with the inputs X = 1, Y = 1, Z = 0, W = 0. With these values, the first condition having the OR operator with the expression X == 1, holds false. As the left side of the OR is false, so the right side expression Y == 1 of it, will be evaluated. Since both sides of the OR operator result in false, so this time, the condition IF (Z == 0 && W == 0) in the ELSE part(at the line 4) will be executed.

The first condition having the AND operator with the expression Z == 0, holds true. Though the left side of the AND operator is true, the right side expression W == 0 will also need to be evaluated. Since both of them are true, then, the statement 5 will be executed resulting in printing 200. Hence, out of total four conditions, four of them got executed this time. The total condition coverage as per formula

Condition Coverage = (Total count of conditions executed / Total count of conditions in the source code) * 100

Condition Coverage = (4 / 4) * 100 = 100 %.

Conclusion

This concludes our comprehensive take on the tutorial on Software Condition Coverage Testing. Weve started with describing what is software condition coverage testing, formula to calculate the software condition coverage percentage, why is software condition coverage testing required, how is software condition coverage testing performed, what are the advantages of software condition coverage testing, and an example to obtain the software condition coverage percentage. This equips you with in-depth knowledge of Software Condition Coverage Testing. It is wise to keep practicing what youve learned and exploring others relevant to Software Testing to deepen your understanding and expand your horizons.

Advertisements