Software Engineering for Students A Programming Approach
Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach
} else { result.setText("you cannot vote"); } 19.5 White box (structural) testing 273 In this program, there are two paths (because the if has two branches) and therefore two sets of data will serve to ensure that all statements are executed at some time during the testing: Test number Data Expected outcome 1 12 cannot vote 2 21 can vote If we are cautious, we realize that errors in programming are often made within the conditions of if and while statements. So we add a further two tests to ensure that the if statement is working correctly: Test number Data Expected outcome 3 17 cannot vote 4 18 can vote Thus we need four sets of data to test this program in a white box fashion. This happens to be the same data that we devised for black box testing. But the reasoning that led to the two sets of data is different. Had the program been written differently, the white box test data would be different. Suppose, for example, the program used an array, named table, with one element for each age specifying whether someone of that age can vote. Then the program is simply the following statement to look up eligibility: result.setText(table[age]); and the white box testing data is different. SELF-TEST QUESTION 19.2 A program’s function is to find the largest of three numbers. Devise white box test data for this section of program. The code is: int a, b, c; int largest; ➞
274 Chapter 19 ■ Testing if (a >= b) { if (a >= c) { largest = a; } else { largest = c; } } else { if (b >= c) { largest = b; } else { largest = c; } } 19.3 In a program to play the game of chess, the player specifies the destination for a move as a pair of integer indices, the row and column number. The program checks that the destination square is valid, that is, not outside the board. Devise white box test data to check that this part of the program is working correctly. The code for this part of the program is: 19.6 ● Other testing methods Stepping through code if ((row > 8) || (row < 1)) { JOptionPane.showMessageDialog(null, "error"); } if ((col > 8) || (col < 1)) { JOptionPane.showMessageDialog(null, "error"); } Some debuggers allow the user to step through a program, executing just one instruction at a time. This is sometimes called single-shotting. Each time you execute one instruction you can see which path of execution has been taken. You can also see (or watch) the values of variables. It is rather like an automated structured walkthrough. In this form of testing, you concentrate on the variables and closely check their values as they are changed by the program to verify that they have been changed correctly. A debugger is usually used for debugging (locating a bug); here it is used for testing (establishing the existence of a bug).
- Page 245 and 246: 222 Chapter 16 ■ Programming in t
- Page 247 and 248: 224 Chapter 16 ■ Programming in t
- Page 249 and 250: 226 Chapter 16 ■ Programming in t
- Page 251 and 252: 228 Chapter 16 ■ Programming in t
- Page 253 and 254: 230 Chapter 16 ■ Programming in t
- Page 255 and 256: 232 Chapter 16 ■ Programming in t
- Page 257 and 258: 234 Chapter 16 ■ Programming in t
- Page 259 and 260: 236 Chapter 16 ■ Programming in t
- Page 261 and 262: 238 Chapter 17 ■ Software robustn
- Page 263 and 264: 240 Chapter 17 ■ Software robustn
- Page 265 and 266: 242 Chapter 17 ■ Software robustn
- Page 267 and 268: 244 Chapter 17 ■ Software robustn
- Page 269 and 270: 246 Chapter 17 ■ Software robustn
- Page 271 and 272: 248 Chapter 17 ■ Software robustn
- Page 273 and 274: 250 Chapter 17 ■ Software robustn
- Page 275 and 276: 252 Chapter 17 ■ Software robustn
- Page 277 and 278: 254 Chapter 17 ■ Software robustn
- Page 279 and 280: 256 Chapter 17 ■ Software robustn
- Page 281 and 282: 258 Chapter 17 ■ Software robustn
- Page 283 and 284: 260 Chapter 18 ■ Scripting GNU/Li
- Page 285 and 286: 262 Chapter 18 ■ Scripting In sum
- Page 288: PART D VERIFICATION
- Page 291 and 292: 268 Chapter 19 ■ Testing We begin
- Page 293 and 294: 270 Chapter 19 ■ Testing within a
- Page 295: 272 Chapter 19 ■ Testing Test num
- Page 299 and 300: 276 Chapter 19 ■ Testing 3. apply
- Page 301 and 302: 278 Chapter 19 ■ Testing made con
- Page 303 and 304: 280 Chapter 19 ■ Testing 19.3 Dev
- Page 305 and 306: 282 Chapter 19 ■ Testing 19.2 The
- Page 307 and 308: 284 Chapter 20 ■ Groups The term
- Page 309 and 310: 286 Chapter 20 ■ Groups Of course
- Page 311 and 312: 288 Chapter 20 ■ Groups • Exerc
- Page 314 and 315: CHAPTER 21 This chapter explains: 2
- Page 316 and 317: Stage Input Output 21.3 Feedback be
- Page 318 and 319: Summary The essence and the strengt
- Page 320 and 321: CHAPTER 22 This chapter: 22.1 ● I
- Page 322 and 323: 22.2 The spiral model 299 to try to
- Page 324 and 325: 22.4 ● Discussion Exercises 301 A
- Page 326 and 327: CHAPTER 23 Prototyping This chapter
- Page 328 and 329: Therefore, in summary: ■ the prod
- Page 330 and 331: 23.5 Evolutionary prototyping 307 U
- Page 332 and 333: Reuse components 23.6 Rapid prototy
- Page 334 and 335: Pitfalls For users, the problems of
- Page 336 and 337: Answers to self-test questions 313
- Page 338 and 339: 24.2 ● Big-bang implementation 24
- Page 340 and 341: Tested component Figure 24.1 Top-do
- Page 342 and 343: 24.7 ● Use case driven implementa
- Page 344 and 345: ■ middle-out ■ use case based.
274 Chapter 19 ■ Testing<br />
if (a >= b) {<br />
if (a >= c) {<br />
largest = a;<br />
}<br />
else {<br />
largest = c;<br />
}<br />
}<br />
else {<br />
if (b >= c) {<br />
largest = b;<br />
}<br />
else {<br />
largest = c;<br />
}<br />
}<br />
19.3 In a program to play the game of chess, the player specifies the destination<br />
<strong>for</strong> a move as a pair of integer indices, the row and column number.<br />
The program checks that the destination square is valid, that is, not<br />
outside the board. Devise white box test data to check that this part of<br />
the program is working correctly.<br />
The code <strong>for</strong> this part of the program is:<br />
19.6 ● Other testing methods<br />
Stepping through code<br />
if ((row > 8) || (row < 1)) {<br />
JOptionPane.showMessageDialog(null, "error");<br />
}<br />
if ((col > 8) || (col < 1)) {<br />
JOptionPane.showMessageDialog(null, "error");<br />
}<br />
Some debuggers allow the user to step through a program, executing just one instruction<br />
at a time. This is sometimes called single-shotting. Each time you execute one<br />
instruction you can see which path of execution has been taken. You can also see (or<br />
watch) the values of variables. It is rather like an automated structured walkthrough.<br />
In this <strong>for</strong>m of testing, you concentrate on the variables and closely check their values<br />
as they are changed by the program to verify that they have been changed correctly.<br />
A debugger is usually used <strong>for</strong> debugging (locating a bug); here it is used <strong>for</strong><br />
testing (establishing the existence of a bug).