statement coverage

How to do white box testing

The article for today is about white box testing.I had written article about white box testing in this blog but that time it was only introduction of white box testing.This article concern with how to do white box testing.

The procedure of White box testing is normally saparated into 3 topic as follow

1.Statement Coverage
It is the testing to verify that all instructions or code must be executed at least one time.We can specify one or more than one test case for doing statement coverage testing (there may be a chance that one test case is not cover all the code we need to test).Below is an example demonstate how to do statement coverage testing.

Suppose you have a piece of code to test like this

software engineering How to do white box testing

Code1

If you determin ‘C’ as the test case then the coverage reach 100% (pass through all line of code) and only one test case is sufficient for doing Statement Coverage for this code.

Advantage of Statement Coverage.
1.To ensure that all source code can be reached at least for one time.
2.It is suitable for making Performance profiling because it can be applied directly to object code without processing source code.

Disadvantage of Statement Coverage.
1.It is insensitive to logical operators such as OR (||),AND (&&) etc.
2.If your source code have a lot of IF-ELSEIF-ELSE statements or contain consecutive switch labels then the test case used for doing Statement Coverage will be increased respectively.

2. Branch Coverage (Condition judgment Coverage)
It is the testing to verify that all branches and instructions must be executed at least one time (Concentrate on testing to cover every branches or decision points in the code).It is the easiest way to perform testing of path or workflow of program.

Please consider the code below and its explanation to understand the operation of Branch Coverage testing.

software engineering How to do white box testing

code2

In the above code we need only two test case to cover all the branches (also all instructions too), they are…
Test case #1 : Input n1 = 1 , n2 = 1
Test case #2 : Input n1 = 2 , n2 = 0

Advantage of Branch Coverage.
1.To validate all branches in the code can be reached and ensure that no branches lead to abnormal of the program’s operation.
2.It eliminate problems that occur with Statement Coverage testing.

Disadvantage of Branch Coverage.
1.There may be other condition that can be used for decision making.For the example, statement “if((b == TRUE) || functionA())”, in this statement we can define only test case with “B = TRUE” and this test case is cover this branch but functionA() isn’t tested.

3.Condition Coverage/Multiple Condition Coverage

It is the testing to verify that all condition expression within each branch will be tested (the true and the false condition of each sub-expression within the decision branch must be tested at least one time ).
It is more intensive testing than Branch Coverage and Statement Coverage.Multiple Condition Coverage has detail of testing more than Condition Coverage.Its test cases are larger than test case of Condition
Coverage because it ensures that all possible combination of conditions of sub-expression within each branch must be tested.

Please consider the code below for Condition Coverage testing.

software engineering How to do white box testing

code3

If you want to test above code by using Condition Coverage you must specify two test
cases to cover all sub-expressions in this branch.The test cases are as follow…

Test case #1: Input n1 = 60 , n2 = 70
Test case #2: Input n1 = 40 , n2 = 110

If you want to test above code with Multiple Condition Coverage you must specify four
test cases to cover all combination of possible condition of sub-expressions in this branch and the test cases look like these

Test case #1: Input n1 = 60 , n2 = 70
Test case #2: Input n1 = 60 , n2 = 110
Test case #3: Input n1 = 40 , n2 = 70
Test case #4: Input n1 = 40 , n2 = 110

Advantage of Condition/Multiple Condition coverage.
1.It is very thorough testing and the bugs are normally found by this kind of testing.

Disadvantage..
1.If the decision branch contain lots of sub-expressions or has very complex boolean expressions , the tester will have to define a large number of test cases.

Thank you,
jitkasem pintaya.

Reference site:
1.MindBlaze Blog
2.Bullseye
3.The paper from utwente.nl by Arnold Zanderink

Incoming search terms for the article:

Get Adobe Flash playerPlugin by wpburn.com wordpress themes