Sunday, April 19, 2009

What is Basis Path Testing?

Basis Path Testing

Testing that fulfills the requirements of branch testing & also tests all of the independent paths that could be used to construct any arbitrary path through the computer program.

Basis Path Testing is a whitebox testing technique that identifies test cases based on the flows or logical paths that can be taken through the program. A basis path is a unique path through the program where no iterations are allowed. Basis Paths are atomic level paths and all possible paths through the system are linear combinations of them. [Source]

Basis Path Testing Example

procedure delete_element (int value, int array_size, int array[])
{
1 int I; /* loop counter */
location = array_size + 1; /* location of value to delete */
/* find the location of the value */
2 for I = 1 to array_size
3 if ( array[I] == value )
4 location = I;
end if;
end for;
/* move each element after the target by one space */
5 for I = location to array_size
6 array[I] = array[I+1];
end for;
7 array_size --;
}



Basis Pathsvaluearray sizearray contentsresult
1 2 5 7na0naPASS
1 2 5 6 7impossible path - to skip node 3, size must be 0, but then 5 always goes to 7

1 2 3 2 5 6 7
impossible path - "1 2 3 2" size=1 and value not in array, but then 5 would go to 7
1 2 3 4 2 5 6 710110FAIL - array out of bounds

the follow tests do exercise each decision as both True and False
1 2 5 7na0naPASS
1 2 3 2 5 710120PASS
1 2 3 4 2 5 7 impossible path - node 4 sets "location" which forces 5 to go to 6
1 2 3 4 2 5 6 7 10110FAIL - array out of bounds

[Source of Example]

Few resources on Basis Path Testing:

Basis Path Testing and its examples. Below paper also gives clear difference between Path and Basis Path testing.
Basis Path Testing Paper

Basis Path Testing and Steps to perform Basis Path Testing with example.
Basis Path Testing with example

Also See:
Statement Coverage

Branch Testing

Path Testing