Fault,Error與Failure的聯系與區別


 

 

Fault

可能導致程序失敗的因素,可理解成具體的代碼。

Error

在程序運行過程中與設計時的預先設想不一致的情況,如變量值錯誤,錯誤的運行路徑等。

Failure

當一程序不能完成所要求的功能時,即失敗。 

 

函數findLast

  1. Identify the fault.

在邊界判斷時出錯 在i=0 時退出循環,沒有檢驗第一個int值。

for循環中的條件判斷應為:(int i=x.length-1; i > =0; i--)

2. If possible, identify a test case that does not execute the fault. (Reachability)

test: x=[]

直接拋出空指針異常而不執行以后的代碼,所以沒有執行fault

  1. If possible, identify a test case that executes the fault, but does not result in an error state.

test: x=[1, 2, 3]; y = 2

Expected= 1

執行了含有fault的代碼在產生error返回了正確結果

4. If possible identify a test case that results in an error, but not a failure.

test: x=[2, 4, 5]; y = 1

Expected = -1

沒有遍歷到x[0],直接返回了-1,因此執行了error但是沒有產生 failure

 

函數lastZero

1、 Identify the fault.

應該從后往前遍歷,for循環中的條件判斷應為:(int i=x.length-1; i > =0; i--);

2、 If possible, identify a test case that does not execute the fault. (Reachability)

test: x=[]

3、 If possible, identify a test case that executes the fault, but does not result in an error state.

test: x=[3, 2, 1];

Expected = -1

遍歷了沒有發現0 沒有進入到error的情況。

4、 If possible identify a test case that results in an error, but not a failure.

test: x=[1, 2, 0]

Expected = 2

發生了error沒有發生failure

返回了第一個0的位置 但只有一個0,結果正確,代碼邏輯錯誤。 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM