斷定中條件的各類組合都至少被執行一次python
一、知足條件組合覆蓋的用例必定知足語句覆蓋
二、知足條件組合覆蓋的用例必定知足條件覆蓋
三、知足條件組合覆蓋的用例必定知足斷定覆蓋
四、知足條件組合覆蓋的用例必定知足條件斷定覆蓋
五、條件組合覆蓋沒有考慮各斷定結果(真或假)組合狀況,不知足路徑覆蓋
六、條件組合數量大,設計測試用例的時間花費較多測試
demo.py設計
#encoding:utf-8 A = int(input('請輸入A的值')) B = int(input('請輸入B的值')) X = int(input('請輸入X的值')) if A > 1 and B == 0: X = X / A if A == 2 or X > 1: X = X + 1 print('結束')
用例編號 | 測試用例 | 覆蓋條件 | 覆蓋路徑 | 預期結果 |
---|---|---|---|---|
1 | A=2,B=0,X=4 | (A>1) and (B== 0), (A==2) or (X>1) | a-c-e | X = 3 |
2 | A=2,B=1,X=1 | (A>1) and (B!=0), (A==2) or (X<=1) | a-b-e | X = 2 |
3 | A=1,B=0,X=2 | (A<=1) and (B==0), (A!=2) or (X>1) | a-b-e | X = 3 |
4 | A=1,B=1,X=1 | (A<=1) and (B!=0), (A!=2) or (X<=1) | a-b-d | X = 1 |
執行用例1 ,斷定(A > 1 and B == 0)爲真 ,執行 X = X / A, X=2;
斷定(A == 2 or X > 1)爲真,執行X = X + 1 ;
輸出 X = 3 ;
程序結束code
執行用例2 ,斷定(A > 1 and B == 0)爲假 ,不執行 X = X / A ;
斷定(A == 2 or X > 1)爲真,執行X = X + 1 ,X=2 ;
輸出 X = 2 ;
程序結束blog
執行用例3 ,斷定(A > 1 and B == 0)爲假 ,不執行 X = X / A ;
斷定(A == 2 or X > 1)爲真,執行X = X + 1 ,X=2 ;
輸出 X = 3 ;
程序結束utf-8
執行用例4 ,斷定(A > 1 and B == 0)爲假,不執行X = X / A ;
斷定(A == 2 or X > 1)爲假,不執行X = X + 1 ;
輸出 X = 1 ;
程序結束ci
從上述用例能夠得出:
一、知足條件斷定覆蓋的測試用例知足語句覆蓋
二、知足條件斷定覆蓋的測試用例知足條件覆蓋,斷定覆蓋 ,條件斷定覆蓋
三、上述用例未考慮每一個斷定的真假組合狀況(路徑覆蓋),程序全部路徑沒有覆蓋input
# encoding:utf-8 import unittest class TestDemo(unittest.TestCase): def demo(self, A, B, X): if A > 1 and B == 0: X = X / A if A == 2 or X > 1: X = X + 1 return X def test_demo_with_conditional_combination_coverage_1(self): ''' 使用條件組合覆蓋測試 方法demo A=2,B=0,X=4 ''' X = self.demo(A=2, B=0, X=4) expected = 3 self.assertEqual(expected, X) def test_demo_with_conditional_combination_coverage_2(self): ''' 使用條件組合覆蓋測試 方法demo A=2,B=1,X=1 ''' X = self.demo(A=2, B=1, X=1) expected = 2 self.assertEqual(expected, X) def test_demo_with_conditional_combination_coverage_3(self): ''' 使用條件組合覆蓋測試 方法demo A=1,B=0,X=2 ''' X = self.demo(A=1, B=0, X=2) expected = 3 self.assertEqual(expected, X) def test_demo_with_conditional_and_decision_coverage_4(self): ''' 使用條件組合覆蓋測試 方法demo A=1,B=1,X=1 ''' X = self.demo(A=1, B=1, X=1) expected = 1 self.assertEqual(expected, X) if __name__ == '__main__': unittest.main()