測試code所有可能的路徑
if x > 3:
print "Hi"
else:
print "Bye"
if y = 5:
print "Good"
else:
print "Bad"
總共會有4個test cases => 每個path都要清到
input A & B
C = A + B
if C > 100:
print "ITS DONE"
if A > 50:
print "ITS PENDING"
END IF
總共會有4個test cases => 每個path都要清到
def foo(x, y):
for i in range(x):
something()
if y:
somethingElse()
以這種情形來說,沒有辦法去測試所有的Path,因為可能有無限個X的值,所以沒辦法達到100% Path coverage
這種情形又稱為 exhaustive testing,所以大多數的時候,Path coverage 100% 是沒有辦法達到的
def x(a, b, c):
if a & b & c:
print("Hi")
可能的測項
Test Case | A | B | C | Outcome |
---|---|---|---|---|
1 | T | T | T | T |
2 | T | T | F | F |
3 | T | F | T | F |
4 | T | F | F | F |
5 | F | T | T | F |
6 | F | T | F | F |
7 | F | F | T | F |
8 | F | F | F | F |
這時我們要找一個條件是會影響到outcome的
所以總結來說,我們只要測試以下測項就能達到100% MCDC Coverage
Test Case | A | B | C | Outcome |
---|---|---|---|---|
1 | T | T | T | T |
2 | T | T | F | F |
3 | T | F | T | F |
5 | F | T | T | F |
def x(a, b, c):
if a | b & c:
print("Hi")
可能的測項
Test Case | A | B | C | Outcome |
---|---|---|---|---|
1 | T | T | T | T |
2 | T | T | F | T |
3 | T | F | T | T |
4 | T | F | F | T |
5 | F | T | T | T |
6 | F | T | F | F |
7 | F | F | T | F |
8 | F | F | F | F |
這時我們要找一個條件是會影響到outcome的 |
所以總結來說,我們只要測試以下測項就能達到100% MCDC Coverage
Test Case | A | B | C | Outcome |
---|---|---|---|---|
2 | T | T | F | T |
5 | F | T | T | T |
6 | F | T | F | F |
7 | F | F | T | F |
count = int(input("enter your number"))
while (couont < 20) & (count > 0):
print(f"The count is: {count}")
count = count + 1
print("Good bye!")
Steps:
count = 20
count = 19
count = 18
count = 10
couont = 1
, count = 0
, count = 2
count_1 = int(input("enter first number"))
count_2 = int(input("enter second number"))
for i in range(count_1):
for j in range(count_2):
print(i, j)
if i > 20 or j > 20:
break
print("Good bye!")
Steps:
count_1 = 1, count_2 = 0
count_1 = 1, count_2 = 1
count_1 = 1, count_2 = 2
count_1 = 1, count_2 = 5
本文章同步發布於個人blogger。