軟體測試(二)之 Failure, Error & Fault

來源:互聯網
上載者:User

標籤:

知識回顧

  軟體測試中的錯誤主要分為三種:Failure, Error 和 Fault

  下面就分析一下它們的不同:

  Fault的定義:可能導致系統或功能 失效的異常條件( Abnormal condition that can cause an element or an item to fail.),可譯為 “故障”。     Error的定義:計算、觀察或測量 值或條件,與真實、規定或理論上正確的 值或條件之間的差異(Discrepancy between a computed, observed or measured value or condition and the true, specified, or theoretically           correct value or condition.),可譯為 “錯誤”。Error是能夠導致系統出現Failure的 系統內部狀態。 

  Failure的定義:當一個系統不能執行所要求的功能時,即為Failure,可譯為“失效”。(Termination of the ability of an element or an item to perform a function as required.)

     三者關係分析:
  • 由於人類試圖通過上述3個基本術語來覆蓋所有現實中的失效情境,所以就有“Fault -> Error -> Failure”。即,故障發生了,會導致錯誤,錯誤有可能造成系統功能的減弱或喪失
  • 當Fault是另外一個組件/系統的失效時,則有Failure (Fault) -> Error -> Failure;當將Fault說成是某組件狀態Error時,則有Error (Fault) -> Error -> Failure
  • 事實上,這是一種遞迴迴圈的關係,遞迴關係要成立必須有一個明確的結束條件,這個條件就是要找出Root Cause,否則將無法完成一個失效分析。    

 

  舉例

  病人告訴醫生自己的各種癥狀,身體沒有健康地工作 – Failures 

  醫生想找出疾病的根源,如病毒 – Fault

  病人身體狀態異常,比如血壓較高,心跳不規律等 – Errors

 

執行個體(HOMEWORK2)

   程式1:

 1 public int findLast (int[] x, int y)  2 { //Effects: If x==null throw                 3         NullPointerException  4    // else return the index of the last element  5    // in x that equals y.  6    // If no such element exists, return -1 7    for (int i=x.length-1; i > 0; i--) 8    { 9         if (x[i] == y) 10        { 11           return i; 12         } 13     }14      return -1; 15 } 16 // test: x=[2, 3, 5]; y = 2 17 // Expected = 0       

 

  Solution:

  1.Fault: 迴圈條件沒設定好,i > 0會導致迴圈無法進行到數組第一項,應該改成 i >= 0。

   2.數組x為空白時,會拋出null 指標錯誤,迴圈無法執行,也不會執行上面敘述的Fault。

   3.只要滿足數組x[0]不是與y相等的唯一的元素即可避免Error,比如測試案例 x = [1, 2, 3, 4, 5, 6],  y = 2, 這樣得到返回結果 Expected = 1, 結果是正確的。

     4.當數組只有一個元素的時候,由於迴圈無法訪問第一個元素(x[0]),所以迴圈無法進行,永遠返回-1,導致Error。此時Failure產生未知, 如果這唯一的元素與y不相等,則Failure也不會產生。測試案例 x = [1], y = 2,此時   返回-1,只有Error,無Failure。

 

  程式2

 1 public static int lastZero (int[] x) { 2     // Effects: if x==null throw NullPointerException 3     // else return the index of the LAST 0 in x. 4     // Return -1 if 0 does not occur in x 5     for (int i = 0; i < x.length; i++) 6     { 7         if (x[i] == 0) 8         { 9             return i;10         } 11     } 12     return -1;13 }14 // test: x=[0, 1, 0]15 // Expected = 2

 

  Solution:

  1.Fault: 迴圈錯誤,從前往後遍曆,遇到第一個0便返回其下標,迴圈應改為for (int i=x.length-1; i >= 0; i--)。

   2.由於該程式從前往後遍曆,迴圈至少執行一次,所以總會執行該Fault。

   3.迴圈如果無法執行便不會導致Error,即數組為空白。另外若數組只有一個元素,這樣不論如何遍曆結果也相同,也不會引發Error。

     4.當數組有一個以上元素且只有一個元素為0時,此時迴圈返回的是第一個等於0的元素的下標,導致Error。但是由於只有一個元素等於0, 所以同時這也是最後一個等於0的元素的下標,則Failure不會產生。測試案例 x =

       [1,0,1],Expected=1,此時只有Error,無Failure。

 

軟體測試(二)之 Failure, Error & Fault

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.