基本路徑測試



什麼是基本路徑測試?

基本路徑測試是一種結構化測試或白盒測試技術,用於設計旨在至少檢查所有可能的執行路徑的測試用例。為所有可能的路徑建立和執行測試會導致 100% 的語句覆蓋率和 100% 的分支覆蓋率。

示例

Function fn_delete_element (int value, int array_size, int array[])
{
	1 int i;
	location = array_size + 1; 

	2 for i = 1 to array_size
	3 if ( array[i] == value )
	4 location = i;
	 end if;
	 end for;

	5 for i = location to array_size
	6 array[i] = array[i+1];
	end for;
	7 array_size --;
} 

計算獨立路徑的步驟

步驟 1:繪製所考慮的功能/程式的流程圖,如下所示

Basis Path Testing in Test Life Cycle

步驟 2:確定獨立路徑。

Path 1:  1 - 2 - 5 - 7 
Path 2:  1 - 2 - 5 - 6 - 7 
Path 3:  1 - 2 - 3 - 2 - 5 - 6 - 7
Path 4:  1 - 2 - 3 - 4 - 2 - 5 - 6 - 7
廣告