Showing posts with label White box testing. Show all posts
Showing posts with label White box testing. Show all posts

Friday, March 29, 2013

Multiple Condition Coverage

Multiple Condition Coverage is also known as Condition Combination Coverage.

In Multiple Condition Coverage for each decision all the combinations of conditions should be evaluated.

Let's take an example:

    if (A||B)
    then
    print C

Here we have 2 Boolean expressions A and B, so the test set for Multiple Condition Coverage will be:

    TEST CASE1: A=TRUE, B=TRUE
    TEST CASE2: A=TRUE, B=FALSE
    TEST CASE3: A=FALSE, B=TRUE
    TEST CASE4: A=FALSE, B=FALSE

As you can see that there are 4 test cases for 2 conditions. Similarly there will be 8 test cases for 3 conditions.

So you can say that if there are n conditions, there will be 2^n tests.

Multiple Condition Decision Coverage

Multiple Condition Decision Coverage(MCDC) is also known as Modified Condition Decision Coverage.

In MCDC each condition should be evaluated at least once which affects the decision outcome independently.

Example for MCDC

if {(X or Y) and Z} then

To satisfy condition coverage, each Boolean expression X,Y and Z in above statement should be evaluated to TRUE and FALSE at least one time.

The TEST CASES for condition coverage will be:

    TEST CASE1: X=TRUE, Y=TRUE, Z=TRUE
    TEST CASE2: X=FALSE, Y=FALSE, Z=FALSE

To satisfy the decision coverage we need to ensure that the IF statement evaluates to TRUE and FALSE at least once. So the test set will be:

    TEST CASE1: X=TRUE, Y=TRUE, Z=TRUE
    TEST CASE2: X=FALSE, Y=FALSE, Z=FALSE

However for MCDC the above test cases are not sufficient because in MCDC each Boolean variable should be evaluated to TRUE and FALSE at least once and also affect the decision outcome.

So to ensure MCDC we need 4 more test cases.

    TEST CASE3: X=FALSE, Y=FALSE, Z=TRUE
    TEST CASE4: X=FALSE, Y=TRUE, Z=TRUE
    TEST CASE5: X=FALSE, Y=TRUE, Z=FALSE
    TEST CASE6: X=TRUE, Y=FALSE, Z=TRUE

    In test case 3 decision outcome is FALSE
    In test case 4 decision outcome is TRUE
    In test case 5 decision outcome is FALSE
    In test case 6 decision outcome is TRUE

So in the above test cases you can see that the change in the value of Boolean variables made a change in decision outcomes. 

Condition Coverage Or Predicate Coverage

Condition coverage is also known as Predicate Coverage
Condition coverage is seen for Boolean expression, condition coverage ensures whether all the Boolean expressions have been evaluated to both TRUE and FALSE.

Let us take an example to explain Condition Coverage

    IF ("X && Y")

In order to suffice valid condition coverage for this pseudo-code following tests will be sufficient.

    TEST 1: X=TRUE, Y=FALSE
    TEST 2: X=FALSE, Y=TRUE

Note: 100% condition coverage does not guarantee 100% decision coverage.

Decision Coverage Or Branch Coverage

Decision Coverage is also known as Branch Coverage.

Whenever there are two or more possible exits from the statement like an IF statement, a DO-WHILE or a CASE statement it is known as decision because in all these statements there are two outcomes, either TRUE or FALSE.

With the loop control statement like DO-WHILE or IF statement the outcome is either TRUE or FALSE and decision coverage ensures that each outcome (i.e. TRUE and FALSE) of control statement has been executed at least once.

Alternatively you can say that control statement IF has been evaluated both to TRUE and FALSE.

The formula to calculate decision coverage is:
Decision Coverage=DC
DC=(Number of decision outcomes executed/Total number of decision outcomes)*100%

Research in the industries have shown that even if through functional testing has been done it only achieves 40% to 60% decision coverage.

Decision coverage is stronger that statement coverage and it requires more test cases to achieve 100% decision coverage.

Let us take one example to explain decision coverage:

    READ X
    READ Y
    IF "X > Y"
    PRINT X is greater that Y
    ENDIF



To get 100% statement coverage only one test case is sufficient for this pseudo-code.

    TEST CASE 1: X=10 Y=5


However this test case won't give you 100% decision coverage as the FALSE condition of the IF statement is not exercised.

In order to achieve 100% decision coverage we need to exercise the FALSE condition of the IF statement which will be covered when X is less than Y.
So the final TEST SET for 100% decision coverage will be:

    TEST CASE 1: X=10, Y=5
    TEST CASE 2: X=2, Y=10


Note: 100% decision coverage guarantees 100% statement coverage but 100% statement coverage does not guarantee 100% decision coverage.

Statement Coverage Or Line Coverage

Statement coverage is also known as line coverage.
The formula to calculate statement coverage is:

Statement Coverage=SC
SC=(Number of statements exercised/Total number of statements)*100

Studies in the software industry have shown that black-box testing may actually achieve only 60% to 75% statement coverage, this leaves around 25% to 40% of the statements untested.

To illustrate the principles of code coverage let's take one pseudo-code which is not specific to any programming language. We have numbered the code lines just to illustrate the statement coverage example however this may not always be correct.

    READ X
    READ Y
    IF X>Y
    PRINT “X is greater than Y”
    ENDIF

Let us see how can we achieve 100% code coverage for this pseudo-code, we can have 100% coverage by just one test set in which variable X is always greater than variable Y.

    TEST SET 1: X=10, Y=5

A statement may be a single line or it may be spread over several lines. A statement can also contain more than one statement. Some code coverage tools group statements that are always executed together in a block and consider them as one statement.

White Box Testing

White-box testing is concerned with testing, the implementation of the program. The intent of this testing is not to exercise all the different input or output conditions but to exercise the different programming structures and data structures used in the program.

White-box testing is also called as Structural Testing or Glass box testing. It is a good practice to perform white box testing during the unit testing phase.

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...