UNIT TESTING : WHITEBOX TESTING
UNIT TESTING : WHITEBOX TESTING
eMail Addr : heriyanto.lucky@gmail.com : dewa_emas@yahoo.com Contact No : 081318170013
Adalah testing yang diturunkan dari “pengetahuan” tentang
k
d
i
l
i
struktur dan implementasi program
Nama lain : glass box, structural, clear box atau open box
testing
harus tahu secara detail tetang perangkat lunak yang akan di
uji.
Untuk pengujian yang lengkap maka suatu perangkat lunak
Untuk pengujian yang lengkap maka suatu perangkat lunak
harus diuji dengan white box dan black box testing
Idealnya tim penguji mengikutsertakan programmer dari
sistem yang akan diuji tersebut
sistem yang akan diuji tersebut
Menguji setiap jalur independent
g j
p j
p
Menguji keputusan logic (true atau falsa)
Menguji Loops dan batasannya
Menguji Loops dan batasannya
White-box (or clear-box) testing implies having access to the code,
being able to see it and review it
being able to see it and review it.
Static white-box testing is the process of carefully and methodically
reviewing the software design, architecture, or code for bugs without
executing it. It's sometimes referred to as structural analysis.
executing it. It s sometimes referred to as structural analysis.
The obvious reason to perform static white-box testing is to find
bugs early and to find bugs that would be difficult to uncover or
isolate with dynamic black-box testing. Having a team of testers
concentrate their efforts on the design of the software at this early
stage of development is highly cost effective.
Formal review adalah kegiatan diskusi/rapat dalam static white-box testing
untuk mempelajari dan menguji desain, alur logika, dan kode program, yang
dilakukan oleh tester dibantu oleh programmer.
p g
¾ Identify Problems. The goal of the review is to find problems with the software not just
items that are wrong, but missing items as well. All criticism should be directed at the design or code, not the person who created it. Participants shouldn't take any criticism personally. Leave your egos, emotions, and sensitive feelings at the door.
¾ Follow Rules. A fixed set of rules should be followed. They may set the amount of code
to be reviewed (usually a couple hundred lines), how much time will be spent (a couple hours), what can be commented on, and so on. This is important so that the participants know what their roles are and what they should expect. It helps the review run more smoothly.
¾ Prepare. Each participant is expected to prepare for and contribute to the review.
Depending on the type of review, participants may have different roles. They need to know what their duties and responsibilities are and be ready to actively fulfill them at
h i M f h bl f d h h h i f d d i
the review. Most of the problems found through the review process are found during preparation, not at the actual review.
¾ Write a Report. The review group must produce a written report summarizing the
results of the review and make that report available to the rest of the product development team It's imperative that others are told the results of the meeting how development team. It s imperative that others are told the results of the meeting how many problems were found, where they were found, and so on.
If the reviews are run properly, they can prove to be a great way to find bugs
early. Think of them as one of the initial nets that catches the big bugs at the
beginning of the process. Sure, smaller bugs will still get through, but they'll
g
g
p
g
g
g
y
be caught in the next testing phases with the smaller nets with the tighter
weave.
Pembuatan testcase didasarkan pada alur
logika
logika
Alur logika : cara dimana suatu bagian dari
program tertentu dieksekusi saat menjalankan
program tertentu dieksekusi saat menjalankan
program.
Alur logika dapat direpresentasikan dengan
g
p
p
g
Komponen Flow graph :
¾
Nodes
(titik)Æ pernyataan (atau sub program) yang akan
ditinjau saat eksekusi program.
¾
Edges
(anak panah) Æ jalur alur logika program untuk
menghubungkan satu pernyataan (atau sub program) dengan
yang lainnya.
¾
Branch nodes
(titik cabang) Æ titik-titik yang mempunyai
(
g)
y g
p y
lebih dari satu anak panah keluaran.
¾
Branch edges
(anak panah cabang) Æ anak panah yang keluar
dari suatu titik cabang
da suatu t t caba g
¾
Paths
(jalur) Æ jalur yang mungkin untuk bergerak dari satu
Eksekusi suatu
test case
menyebabkan
program untuk mengeksekusi pernyataan
program untuk mengeksekusi
pernyataan-pernyataan tertentu, yang berkaitan
dengan jalur tertentu sebagaimana
dengan jalur tertentu, sebagaimana
tergambar pada
flow graph
.
Cakupan cabang, pernyataan dan jalur
Cakupan cabang, pernyataan dan jalur
dibentuk dari eksekusi jalur program yang
berkaitan dengan peninjauan titik, anak
`
Ditentukan dengan menilai proporsi dari
di i j
l h
pernyataan-pernyataan yang ditinjau oleh
sekumpulan
test cases
yang ditentukan.
C k
t
100% jik ti
`
Cakupan pernyataan 100% jika tiap
pernyataan pada program ditinjau
setidaknya minimal sekali tes
setidaknya minimal sekali tes
`
Cakupan pernyataan berkaitan dengan
nodes dari suatu flowgraph
nodes dari suatu flowgraph
Pada contoh gambar
flow
graph
di samping
terdapat 10 titik.
Misal suatu jalur
Misal suatu jalur
eksekusi program
melewati titik-titik A, B,
D H K
D, H, K.
Berarti ada 5 titik dari 10
titik yang dikunjungi,
titik yang dikunjungi,
maka cakupan
`
Cakupan cabang ditentukan dengan menilai
proporsi dari cabang keputusan yang diuji oleh
sekumpulan test cases yang telah ditentukan.
`
Cakupan cabang 100% adalah bilamana tiap
cabang keputusan pada program ditinjau
setidaknya minimal sekali tes
setidaknya minimal sekali tes.
`
Cakupan cabang berkaitan dengan peninjauan
anak panah cabang (branch edges) dari flow
anak panah cabang (branch edges) dari flow
Pada contoh gambar flow
h di
i
t d
t 6
graph di samping, terdapat 6
anak panah cabang.
Misal suatu jalur eksekusi
j
program melewati titik-titik A,
B, D, H, K, maka jalur
tersebut meninjau 2 dari 6
j
anak panah cabang yang
ada, jadi cakupannya
`
Cakupan jalur ditentukan dengan menilai
proporsi eksekusi jalur program yang diuji oleh
sekumpulan test cases yang telah ditentukan.
`
Cakupan jalur 100 % adalah bilamana tiap jalur
pada program dikunjungi setidaknya minimal
sekali tes
sekali tes.
`
Cakupan jalur berkaitan dengan peninjauan jalur
sepanjang flow graph
sepanjang flow graph.
• Berdasarkan contoh flow
graph di atas, terdapat 4 jalur.
• Bila suatu eksekusi jalur pada
program melalui titik titik A B
program melalui titik-titik A, B,
D, H, K, maka eksekusi
tersebut meninjau 1 dari 4
j l
d
j di
jalur yang ada, jadi
Untuk mendisain cakupan dari tes, perlu diketahui
tahap tahap sebagai berikut:
tahap-tahap sebagai berikut:
1.
Menganalisa
source code
untuk membuat
flow
graph
.
g ap
2.
Mengidentifikasi jalur tes untuk mencapai
pemenuhan tes berdasarkan pada
flow graph
.
3.
Mengevaluasi kondisi tes yang akan dicapai dalam
tiap tes.
4
M
b ik
il i
k
d
k l
4.
Memberikan nilai masukan dan keluaran
berdasarkan pada kondisi.
`
Merupakan teknik
white box testing
yang
dikenalkan oleh Tom McCabe [MC76]
dikenalkan oleh Tom McCabe [MC76].
`
Memungkinkan pendisain
test cases
untuk
melakukan pengukuran terhadap kompleksitas
e a u a pe gu u a te adap o p e s tas
logika dari disain prosedural
`
Menggunakan ukuran kompleksitas tsb sebagai
d
d l
k
k l
k b i d i
panduan dalam menentukan kelompok basis dari
jalur eksekusi dimana hal ini akan menjamin
eksekusi tiap pernyataan dalam program
p p
y
p g
`
Identifikasi didasarkan pada jalur, struktur atau
koneksi yang ada dari suatu sistem (
branch
koneksi yang ada dari suatu sistem (
branch
testing)
, karena cabang-cabang dari kode atau
fungsi logika diidentifikasi dan dites
`
Konsep utama basis path :
Tiap
basis path
harus diidentifikasi, tidak boleh ada yang
terabaikan (setidaknya dites 1 kali)
terabaikan (setidaknya dites 1 kali).
Kombinasi dan permutasi dari suatu
basis path
tidak perlu
`
Adalah pengukuran kuantitatif dari kompleksitas logika
program
program.
`
Pada konteks metode
basis path testing
, nilai yang dihitung
bagi
cyclomatic complexity
menentukan jumlah jalur-jalur
yang independen dalam kumpulan basis suatu program dan
yang independen dalam kumpulan basis suatu program dan
memberikan jumlah tes minimal yang harus dilakukan untuk
memastikan bahwa semua pernyataan telah dieksekusi
sekurangnya satu kali.
sekurangnya satu kali.
`
Jalur independen adalah tiap jalur pada program yang
memperlihatkan 1 kelompok baru dari pernyataan proses
atau kondisi baru
atau kondisi baru.
public static int binarySearch( int key, int[] sequence ) { int bottom = 0;
int top = sequence length - 1; int top sequence.length 1; int mid = 0;
int keyPosition = -1;
while( bottom <= top && keyPosition == -1 ) { mid = ( top + bottom ) / 2;
if( sequence[ mid ] == key ) { k P iti id
keyPosition = mid; }
else {
if( sequence[ mid ] < key ) {( q [ ] y ) { bottom = mid + 1; } else { top = mid - 1; } } } } return keyPosition; }
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1 1
1 int top = sequence.length - 1; int mid = 0;
int keyPosition = -1;
1 1
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( [ id ] k ) { if( sequence[ mid ] == key ) {
keyPosition = mid; }
else {
if( sequence[ mid ] < key ) { bottom = mid + 1; } else { top = mid - 1; } } } } return keyPosition; }
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0;
int keyPosition = -1;
1
2
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( [ id ] k ) {
1 2
if( sequence[ mid ] == key ) { keyPosition = mid;
}
else {
if( sequence[ mid ] < key ) { bottom = mid + 1; } else { top = mid - 1; } } } } return keyPosition; }
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; F 1 2 1 2 F
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( [ id ] k ) {
F
if( sequence[ mid ] == key ) { keyPosition = mid;
}
else {
if( sequence[ mid ] < key ) { bottom = mid + 1; } 10 else { top = mid - 1; } } } } return keyPosition; } 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( [ id ] k ) {
F F
3 F
if( sequence[ mid ] == key ) { keyPosition = mid;
}
else {
if( sequence[ mid ] < key ) { bottom = mid + 1; } 10 else { top = mid - 1; } } } } return keyPosition; } 10 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 5 T 5 T
if( sequence[ mid ] < key ) { bottom = mid + 1; } 10 else { top = mid - 1; } } } } return keyPosition; } 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 5 T F 5 T 6
if( sequence[ mid ] < key ) { bottom = mid + 1; } 6 10 else { top = mid - 1; } } } } return keyPosition; } 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 5 T F 5 T 6
if( sequence[ mid ] < key ) { bottom = mid + 1; } 6 10 9 else { top = mid - 1; } } } } return keyPosition; } 9 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 T 5 T F 5 T 6 7 T
if( sequence[ mid ] < key ) { bottom = mid + 1; } 7 T 6 10 9 else { top = mid - 1; } } } } return keyPosition; } 9 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 T 5 T F 5 T 6 7 T 8 F
if( sequence[ mid ] < key ) { bottom = mid + 1; } F 7 T 6 10 9 else { top = mid - 1; } } 8 } } return keyPosition; } 9 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 T 5 T F 5 T 6 7 T 8 F
if( sequence[ mid ] < key ) { bottom = mid + 1; } F 7 T 6 10 9 else { top = mid - 1; } } 8 } } return keyPosition; } 9 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 1 2 F T
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 F 4 T T F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 T 5 T F 5 T 6 7 T 8 F
if( sequence[ mid ] < key ) { bottom = mid + 1; } F 7 T 6 10 9 else { top = mid - 1; } } 8 } } return keyPosition; } 9 10
public static int binarySearch( int key, int[] sequence ) {
int bottom = 0;
i t t l th 1
1
int top = sequence.length - 1; int mid = 0; int keyPosition = -1; 3 T 1 2 3 2 F T F
while( bottom <= top && keyPosition == -1 ) {
mid = ( top + bottom ) / 2; if( 4 [ id ] k ) { T T F F 3 4 T 5 T 6 F
if( sequence[ mid ] == key ) { keyPosition = mid; } else { 6 T 5 T F 5 6 7 T 8 F
if( sequence[ mid ] < key ) { bottom = mid + 1; } F 7 T 6 10 9 else { top = mid - 1; } } 8 } } return keyPosition; } 9 10
`
Setelah pembuatan
p
1flowgraph, tahap
selanjutnya adalah
hit
CC
t k
3 1 2 F T Fmenghitung CC untuk
menentukan jumlah jalur
independen
3 F 4 T 5 T 6 Fp
CC = jml edges-jml
nodes+2
5 6 7 T 8 FCC = 13-10+2
= 5
10 9`
Berdasarkan urutan alurnya,
1`
Berdasarkan urutan alurnya,
didapatkan suatu kelompok
basis flow graph
:
3 1 2 F T F
Jalur 1 = 1-2-10
Jalur 2 = 1-2-3-10
Jalur 3 = 1-2-3-4-6-7-9-2-10
3 F 4 T 5 T 6 FJalur 3 = 1 2 3 4 6 7 9 2 10
Jalur 4 = 1-2-3-4-6-8-9-2-10
Jalur 5 = 1-2-3-4-5-9-2-10
5 6 7 T 8 F 10 9
Buat flowgraph
Hitung CC dan tentukan jalur independen
Buatkan satu testcase berdasarkan jalur independen yang telah
public class Factorial
{
// E l t
!
// Evaluate n!
public static long factorial( int n )
{
Buat flowgraph
Hitung CC dan tentukan
if( n <= 0 ) // base case
return 1;
else
Hitung CC dan tentukan
jalur independen
Buatkan satu testcase
return n * factorial( n - 1 );
}
// Simple test program
berdasarkan jalur
independen yang telah
ditentukan
public static void main( String [ ]
args )
{
ditentukan
for( int i = 1; i <= 10; i++ )
System.out.println( factorial( i
) );
}
}
Dynamic whitebox testing, adalah uji yang dilakukan dengan
mengeksekusi kode program sesuai dengan testcase
mengeksekusi kode program sesuai dengan testcase
Ada 4 area pengujian yang biasanya dilakukan dalam dynamic
whitebox yaitu:
whitebox, yaitu:
`
Mengeksekusi fungsi, prosedur, subrutin, atau library dari suatu
soffware
`
Mengeksekusi software secara utuh dan fokus kepada operasi
`Mengeksekusi software secara utuh, dan fokus kepada operasi
software yang utama
`
Mengeksekusi software di kondisi/lingkungan berbeda sesuai
testcase
`