• Embed Doc
  • Readcast
  • Collections
  • 1
    CommentGo Back
Download
 
Know the Basic White Box Testing Techniques based upon Code Coverage
Some of the basic testing techniques based on code coverage are as under.1)
 
Statement Coverage:
2) Path Coverage:3)
Condition Coverage:4) Function Coverage:
1) Statement Coverage:
In most of the programming languages, the program construct may be a sequential control flow, a two-waydecision statement like if – then – else, a multi-way decision statement like switch or even loops like while, do,repeat until and for.Statement coverage refers to writing test cases that execute each of the program statements. We assume that"more the code covered, the better is the testing of the functionality".For a set of sequential statements (i.e., with no conditional branches), test cases can be designed to runthrough from top to bottom. However, this may not always be true in two casesa) If there are asynchronous exceptions in the code, like divide by zero, then even if we start a test case at thebeginning of a section, the test case may not cover all the statements in that section. Thus, even in case of sequential statements, coverage for all statements may not be achieved.b) A section of code may be entered from multiple points.In case of if then-else statement, if we want to cover all statements then we should also cover the 'then' and'else' parts of the if statement. This means that we should have, for each if-then-else, at least one test case totest the 'then' part and at least one test case to test the 'else' part.The multi-way, switch statement can be reduced to multiple two-way if statements. Thus, to cover all possibleswitch cases, there would be multiple test cases.A good percentage of the defects in programs come about because of loops that do not function properly.More often, loops fail in what are called "boundary conditions". So, we must have test cases that1) Skip the loop completely so that the situation of the termination condition being true before starting the loopis tested.2) Check the loop for n = 1.3) Try covering the loop at the boundary values of n i.e., just below n and just above n.The statement coverage for a program, which is an indication of the percentage of statements actuallyexecuted in a set of tests, can be calculated by the following formulaStatement Coverage = (Total Statements Exercised) / (Total Number of Executable Statements in Program) x100Thus it is evident that as the type of statement progresses from a simple sequential statement to if-then-elseand through loops, the number of test cases required to achieve statement coverage increases. As we havealready seen that exhaustive testing or 100% testing is not possible, so also exhaustive coverage of allstatements in a program will be impossible for all practical purposesHence even if we get high level of the statement coverage, it does not mean that the program is free fromdefects.
 
In a program that implements wrong requirements and if such a code is fully tested with say, 100% coveragealso, it is still a wrong program. Hence 100% code coverage does not mean anything.Let us consider another example here.i = 0 ;if (code = = "y"){statement –1 ;statement –2 ;::statement - n ;}elseresult = {marks / I} * 100 ;In this program, when we test with code = "y", we will get 80% code coverage. But if the data distribution inthe real world is such that 90% of the time, the value of code is not = "y", then, the program will fail 90% of thetime because of the exception-divide by zero. Thus. even with a code coverage of 80%, we are left with adefect that hits the users 90% of the time.The path coverage technique described below overcomes this problem.
2) Path Coverage:
In path coverage technique, we split a program into a number of distinct paths. A program or a part of aprogram can start from the beginning and take any of the paths to its completion. The path coverage of aprogram may be calculated based on the following formulaPath Coverage = (Total Path Exercised) / (Total Number of Paths in Program)
X
100Consider the following flow graph having different paths.
 
Some of the paths are
Path-1:
1 > 2 > 6
Path-2:
1 > 3 > 5 > 6
Path-3:
1 > 3 >4 > 5 > 6
Path-4:
1 > 3 >4 > 2 > 6
 
Regardless of the number of statements in each of these paths, if we can execute these paths, then we wouldhave covered most of the typical scenarios.Path coverage provides a stronger condition of coverage compared to statement coverage as it relates to thevarious logical paths in the program rather than just program statements.
3) Condition Coverage:
In the above example, even if we have covered all the paths possible, it does not mean that the program isfully tested. Path testing is not sufficient, as it does not exercise each part of the Boolean expressions,Relational expressions and so on. This technique of condition coverage or predicate monitors whether everyoperand in a complex logical expression has taken on every True / False value. Obviously, this will mean moretest cases and the number of test cases and the number of test cases will rise exponentially with the number of conditions and Boolean expressions.For example, in if-then-else, there are 2
2
or 4 possible True / False conditions. The condition coverage whichindicates the percentage of conditions covered by a set of test cases, is defined by the following formulaCondition Coverage = (Total Decisions Exercised) / (Total Number of Decisions in Program) x 100Thus it becomes quite clear that this technique of condition coverage is much stronger criteria than pathcoverage, which in turn is a much stronger criteria than statement coverage.
4) Function Coverage:
In this white box testing technique we try to identify how many program functions are covered by test cases.So, while providing function coverage, test cases can be written so as to exercise each of different functions inthe code.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...

Thanks. Great tutorial mate... Here's the Video Tutorial: http://bit.ly/cXQPGN - If you prefer video like myself. Don't get me wrong, I still like ur tutorial!

You must be to leave a comment.
Submit
Characters: ...