Statement Coverage

10.2.1 Statement Coverage

The statement coverage criterion provides for generating sufficient test data to execute each statement of the candidate program at least once. This is a very weak criterion, since the only faults it is likely to expose are those that are so egregious that any exe- cution of the faulty statement will cause an error, and that the error is so extensive that it will propagate and cause a failure; by statement, this criterion usually refers to ele- mentary statements, typically assignment statements and atomic system calls. This criterion can also be applied at a higher level of abstraction than the elementary state- ment, and calls for exercising all the components of a composite system, with the same qualification: it can only expose faulty components that are so egregiously faulty that any execution of these components will sensitize their fault and subsequently prop- agate the resulting error to cause failure. Because this criterion is so weak, a single path may, conceivably, satisfy it, in some simple cases.

As an illustration, we consider the following simple program g:

{int x; int y; read(x); read(y); // assuming x>0, y>0 while (x!=y) {if (x>y) {x=x-y;} else {y=y-x;}}; write(x);}

10.2 CONTROL FLOW COVERAGE 203

Execution of the following path through the program will exercise all the elementary statements:

p: int x; int y; // F0 read(x); read(y);

// F1 ((x!=y)? true); ((x>y)? true); {x=x-y;} // F2 ((x!=y)? true); ((x>y)? false); {y=y-x;} // F3 ((x!=y)? false);

// F4 {write(x);

// F5

The effect of F0 is to let the space of the program be defined by variables is and os of type file stream and variables x and y of type integer; all subsequent functions will

be defined on this space. We find: F 1 = s,s length is ≥ 2 x = head is y = head tail is

is = tail 2 is os = os

The product of F 2 by F 3 yields:

F 2 • F 3 = s,s x > y x −y < y x = x−y y = 2y−x is = is os = os

Whence, the product of F 2 • F 3 by F 4 yields:

F 2 • F 3 • F 4 = s,s x > y x −y < y x = x−y y = 2y−x is = is os = os x = y which we simplify to become:

F 2 • F 3 • F 4 = s,s 2x = 3y x = x−y y = x is = is os = os

Multiplying on the left by F 1 , we find

F 1 • F 2 • F 3 • F 4 = s,s length is ≥ 2 2 × head is = 3 × head tail is

x = head is −head tail is y=x is = tail 2 is os = os

Multiplying on the right by F 5 , we find PF 1 • F 2 • F 3 • F 4 • F 5 = s,s length is ≥ 2 2 × head is = 3 × head tail is

x = head is −head tail is

y=x is = tail 2 is os = os x

204 STRUCTURAL CRITERIA

The domain of this function is: dom P = s,s length is ≥ 2 2 × head is = 3 × head tail is Any element of this domain is a possible test data that satisfies the criterion of

statement coverage; we choose the initial state s defined by:

is = 21,14 os = x= y=

Even though a single path (and a single element in the domain of the path) enabled us to satisfy the criterion of statement coverage, it may be beneficial, in practice, to cover different statements with different paths (whenever possible) to minimize the likelihood of error masking (the longer the path, the more likely it is for an error to be masked). To this effect, we may satisfy the statement coverage with the following two paths:

p1: int x; int y; // F0 read(x); read(y);

// F1 ((x!=y)? true); ((x>y)? true); {x=x-y;}

// F2 ((x!=y)? false);

// F3 {write(x);

// F4 p2: int x; int y;

// F0 read(x); read(y);

// F1 ((x!=y)? true); ((x>y)? false); {y=y-x;} // F2 ((x!=y)? false);

// F3 {write(x);

// F4

We leave it as an exercise to the reader to generate test data from these two paths.

Dokumen yang terkait

Analisis Komparasi Internet Financial Local Government Reporting Pada Website Resmi Kabupaten dan Kota di Jawa Timur The Comparison Analysis of Internet Financial Local Government Reporting on Official Website of Regency and City in East Java

19 819 7

ANTARA IDEALISME DAN KENYATAAN: KEBIJAKAN PENDIDIKAN TIONGHOA PERANAKAN DI SURABAYA PADA MASA PENDUDUKAN JEPANG TAHUN 1942-1945 Between Idealism and Reality: Education Policy of Chinese in Surabaya in the Japanese Era at 1942-1945)

1 29 9

Improving the Eighth Year Students' Tense Achievement and Active Participation by Giving Positive Reinforcement at SMPN 1 Silo in the 2013/2014 Academic Year

7 202 3

Improving the VIII-B Students' listening comprehension ability through note taking and partial dictation techniques at SMPN 3 Jember in the 2006/2007 Academic Year -

0 63 87

The Correlation between students vocabulary master and reading comprehension

16 145 49

Improping student's reading comprehension of descriptive text through textual teaching and learning (CTL)

8 140 133

The correlation between listening skill and pronunciation accuracy : a case study in the firt year of smk vocation higt school pupita bangsa ciputat school year 2005-2006

9 128 37

Perancangan Sistem Informasi Akuntansi Laporan Keuangan Arus Kas Pada PT. Tiki Jalur Nugraha Ekakurir Cabang Bandung Dengan Menggunakan Software Microsoft Visual Basic 6.0 Dan SQL Server 2000 Berbasis Client Server

32 174 203

Pengaruh Kualitas Software Aplikasi pengawasan kredit (C-M@X) Pt.PLN (PERSERO) Distribusi Jawa Barat Dan Banten (DJBB) Terhadap Produktivitas Kerja karyawan UPJ Bandung Utara

5 72 130

Transmission of Greek and Arabic Veteri

0 1 22