Tải bản đầy đủ (.pptx) (37 trang)

Softwaretesting 06 eng

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (316.16 KB, 37 trang )

ソフトウェアテスト
   [6] ホワイトボックステス

Software Testing
[6] White Box Testing Techniques
あまん ひろひさ ひろひさ

阿萬 裕久 裕久( AMAN

Hirohisa )

(C) 2007-2022 Hirohisa AMAN

1


Classification of tests
 black box testing

Explained in Part 4, Exercise in
Session 5

The contents of the program are not seen
(black box), and operation tests are perfor
med based on specifications

 white box testing
Perform operation tests based on the intern
al structure (mainly flowchart)

 random testing


Create test cases randomly and test them
(C) 2007-2022 Hirohisa AMAN

2


white box test method
 How to design test cases by focusing on
the structure of the source program rat
her than the specification
 Test not in line with required specifications
 Dealing with structural complexity (combin
ation of conditions, etc.) in the source prog
ram
 Tests that supplement black box testing

(C) 2007-2022 Hirohisa AMAN

3


White box test method (1)
Statement coverage method
 Execute all statements at least once
 It may not be possible with only one test c
ase (execution path)
 With different test cases, and consider thei
r collection of test cases, It is possible to c
over them all
 The percentage of instructions that could b

e executed is called the instruction covera
ge rate.
 This is also known as C0
(C) 2007-2022 Hirohisa AMAN

4


Example to test
void foo(int x, int y){
int sum, n;
sum = 0;
for ( n = 0; n < x; n++ ){
sum += n;
}
if ( sum < y ){
printf("%dn", sum);
}
else{
printf("%dn", y);
}
}

[input]
Arguments x, y
[output]
Values printed by pr
intf

(C) 2007-2022 Hirohisa AMAN


5


Instruction coverage example: x=
1,y=0
Source code

Execution?

void foo(int x, int y){

---

int sum, n;



sum = 0;



for ( n = 0; n < x; n+
+ ){

Instruction
Coverage
(C0)





sum += n;
}

--○

if ( sum < y ){
printf("%dn", sum);
}
}
else{
else{
printf("%dn", y);
}
}

}
}



← sum = 0 (that‘s why)

------○
---

[Note]
It is necessary to
define in advance

which instructions are
counted as executable.

------(C) 2007-2022 Hirohisa--AMAN

6


Example of 100% instruction cove 100% instruction cove instruction cove
rage
Source code

x=1, y=0

x=1, y=1

total

---

---

---

int sum, n;








sum = 0;



















--○

--○

--○








--------○

--------☓

--------○

--------- 7

---------

void foo(int x, int y){

for ( n = 0; n < x; n+
+ ){
sum += n;
}
if ( sum < y ){
printf("%dn", sum);
}
}
else{
else{
printf("%dn", y);
}
}


}
}

--------(C) 2007-2022 Hirohisa
AMAN


When drawing a flowchart
Test case ① x=1, y=0
START
sum = 0
F.
sum < y

n=0

nn++

F.

If 100% instruction cove some
instructions are
Not running

T.
Sum output

Y output


T.
sum += n
END
(C) 2007-2022 Hirohisa AMAN

8


When drawing a flowchart
Test case ② x=1, y=1
START
sum = 0
F.
sum < y

n=0

nn++

F.

In test case ①
did not run
cover instruction

T.
Sum output

Y output


T.
sum += n
END
(C) 2007-2022 Hirohisa AMAN

9


White box test method (2)
Branch coverage method
 If all conditional branches (if statement,
while statement, for statement), execut
e at least once when it becomes True a
nd when it becomes False
 Again, It would be nice to be able to cover
set of multiple test cases
 Percentage who experienced “T” and “F” of
all conditions is called branch coverage rate
 This is also known as C1
(C) 2007-2022 Hirohisa AMAN

10


Branch coverage example: x=1,
y=0
Source code

Exec?


T, F

---

---

int sum, n;



---

sum = 0;



---

void foo(int x, int y){

for ( n = 0; n < x; n+
+ ){



F




sum += n;

---

}

--○

if ( sum < y ){
printf("%dn", sum);



--F
---

}

---

---

else{

--○

---

printf("%dn", y);
}

}

T

-----

---

---

---

(C) 2007-2022 Hirohisa AMAN

Branch
coverage rate
(C1)


Example of 100% instruction cove 100% instruction cove branch coverag
e rate
Source code

x=1, y=0

x=1, y=1

total

---


---

---

int sum, n;

---

---

---

sum = 0;

---

---

---

void foo(int x, int y){

for ( n = 0; n < x; n+
+ ){
sum += n;

T.

F.

---

}

--- F.

T.

F.
---

T.

F.
---

T. ---

T. --- F.

if ( sum < y ){
printf("%dn", sum);

---

---

---

}


---

---

---

else{

---

---

---

---

---

---

---

---

---

---

---


printf("%dn", y);
}
}

(C) 2007-2022 Hirohisa AMAN

12

---


When drawing a flowchart
Test case ① x=1, y=0
T and F of 100% instruction cove
both
experienc
e

START
F only
sum = 0
F.
sum < y

n=0

nn++


F.

T.
Sum output

Y output

Theref 100% instruction coveore,
Branch
coverage
rate
(C1) = 3/4

T.
sum += n
END
(C) 2007-2022 Hirohisa AMAN

13


When drawing a flowchart
Test case ② x = 1, y = 1
In test case ①
did not run
"T." side cover

START
sum = 0
F.

sum < y

n=0

nn++

F.

T.
Sum output

Y output

T.
sum += n
END
(C) 2007-2022 Hirohisa AMAN

14


Consider another example
 Consider a program that performs si
mple security checks on passwords
[Check items]
 Is password length more than 6 characte
rs?
 Is your password the same as your usern
ame?

(C) 2007-2022 Hirohisa AMAN

15


Example of 100% instruction cove 75% instruction cove branch coverage
test cases

START

pwd length
>= 6




F.

F.

No output



T.

Password
!= Username




(username, password)
① ("taro","")
② ("taro","f 100% instruction coveoobar")
③ ("taro","taro")

T.
OKoutput

END
(C) 2007-2022 Hirohisa AMAN

16


(Note) in the program
“}” does not count as an
instruction

[Exercise 1]
Calculate C0 and C1
 I ran two test ca
ses for the right
code
 (n, limit)
= (2, 1), (-2, 0)

 In this case,
Calculate C0 and
C1


if ( n < 0 ){
n *= -1;
}
sum = 0;
for ( i = 0; i < n; i+
+ ){
sum += i;
if ( sum > limit ){
sum = 0;
}
}
printf("%dn", sum);

(C) 2007-2022 Hirohisa AMAN

17


[Exercise 1] Answer: 100% for
① and ②
test cases

START
i=0
F.

n<0

① ②


i
T.

n *= -1



F.

T.

sum += i


Sum output
sum = 0

i++

(n, limit)
=
① (2, 1)
② (-2, 0)

F.
sum > limit
T.






sum = 0
END
(C) 2007-2022 Hirohisa AMAN

18


[Exercise 2]
Calculate branch coverage
int is_prime(int n){
int k;
is_prime(1);
if ( n < 2 ){
return 0;
is_prime(2);
}
for ( k = 2; k < n; k+
test and calculate t+ ){
he branch coverage
if ( n % k == 0 ){
(C1)
return 0;
}
 
}
(*Drawing a flowchart

return 1;
Not required)
}
(C) 2007-2022 Hirohisa AMAN
19

 Right function


Note for exercise 2
Source code

n=1
実行   条件
条件

int k;

n=1, n=2 for each
While checking whether or
not it is conditional executed

n=2
実行   条件
条件

total

---


---

---

---

---

---

---

---

---

---

---

---

---

---

---

---


---

---

---

---

---

if ( n < 2 ){
return 0;
}
for ( k = 2; k < n; k+
+ ){
if ( n % k == 0 ){
return 0;
}
}
return 1;

(C) 2007-2022 Hirohisa AMAN

20



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×