1. Trang chủ
  2. » Công Nghệ Thông Tin

Testing Computer Software phần 1 pdf

25 352 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 25
Dung lượng 4,05 MB

Nội dung

1 Testing Computer Software Cem Kaner Jack Falk Hung Quoc Nguyen 2 CONTENTS AN EXAMPLE TEST SERIES 3 THE OBJECTIVES AND LIMITS OF TESTING 19 TEST TYPES AND THEIR PLACE IN THE SOFTWARE DEVELOPMENT PROCESS 29 SOFTWARE ERRORS 61 REPORTING AND ANALYZING BUGS 67 THE PROBLEM TRACKING SYSTEM 89 TEST CASE DESIGN 125 TESTING USER MANUALS 144 TESTING TOOLS 154 TEST PLANNING AND TEST DOCUMENTATION 168 TYING IT TOGETHER 219 MANAGING A TESTING GROUP 267 3 AN EXAMPLE TEST SERIES THE REASON FOR THIS CHAPTER Software testing Is partly intuitive but largely systematic. Good testing Involves much more than just running the program a few times to see whether it works. Thorough analysis of the program lets you test more systematically and more effectively. This chapter introduces this book by Illustrating how an experienced tester could approach the early testing of a simple program, To keep the example easy to understand, we made the program almost ridiculously simple. But we did give it some errors that you'll see often In real programs. THE FIRST CYCLE OF TESTING You've been given the program and the following description of it: The program is designed to add two numbers, which you enter. Each number should be one or two digits. The program will echo your entries, then print the sum. Press <Enter> after each number. To start the program, type ADDER. Figure 1 . 1 A first test of the program What you do What happens Type ADDER and press the The screen blanks. You see a question mark at the top of <Enter> key screen. Press 2 A 2 appears after the question mark. Press <Enter> A question mark appears on the next line. Press 'A 3 appears after the second question mark. Press <Enter> A 5 appears on the third line. A couple lines below it is another question mark. 4 THE FIRST CYCLE OF TESTING STEP 1: START WITH AN OBVIOUS AND SIMPLE TEST STEP 1: START WITH AN OBVIOUS AND SIMPLE TEST Take time to familiarize yourself with the program. Check whether the program is stable enough to be tested. Programs submitted for formal testing often crash right away. Waste as little time on them as possible. The first test just adds 2 and 3. Figure 1.1 describes the sequence of events and results. Figure 1.2 shows what the screen looks like at the end of the test. The cursor (the flashing underline character beside the ques- tion mark at the bottom of the screen) shows you where the next number will be displayed. PROBLEM REPORTS ARISING FROM THE FIRST TEST The program worked, in the sense that it accepted 2 and 3, and returned 5. But it still has problems. These are described on Problem Report forms, like the one shown in Figure 1.3. 1. Design Error: Nothing shows you what program this is. How do you know you're in the right program? 2. Design Error: There are no onscreen instructions. How do you know what to do? What if you enter a wrong number? Instructions could easily be displayed OD the screen where they won't be lost, as short printed instructions typically are. 3. Design Error: How do you stop the program? These instructions should appear onscreen too. 4. Coding Error: The sum (5) isn't lined up with the other displayed numbers. Submit one Problem Report for each error. All four errors could fit on the same report, but that's not a good idea. Problems that are grouped together might not be fixed at the same time. The unfixed ones will be lost. If the programmer wants to group them, she can sort the reports herself. To draw attention to related problems, cross-reference their reports. 5 6 THEFIRSTCYCLEOFTESTING _ _ _ _ _ _ _ STEP 2: MAKE SOME NOTES ABOUT WHAT ELSE NEEDS TESTING STEP 2: MAKE SOME NOTES ABOUT WHAT ELSE NEEDS TESTING After your first burst of obvious tests, make notes about what else needs testing. Some of your notes will turn into formal test series: well-documented groups of tests that you will probably use each time you test a new version of the program. Figure 1.4 is a test series that covers the valid inputs to the program—pairs of numbers that the program should add correctly. In the first test, you entered two numbers, didn't try to change them, and examined the result. Another 39,600 tests are similar to this.' It would be crazy to run them all. Figure 1.4 includes only eight of them. How did we narrow it down to these eight? A minor factor in determining specific values was that we wanted to use each digit at least once. Beyond that, we restricted the choices to the tests that we considered most likely to reveal problems. A powerful technique for finding problem cases is to look for boundary conditions. 1 To confirm that there are 39,601 possible tests, consider Calculating the number of possible test cases is an appli- this. There are 199 valid numbers ranging from -99 to 99. cation of a branch of mathematics called combinatorial You can enter any of these as the first number. Similarly, analysis. It's often a simple application. You can get the you can enter any of these 199 as the second number. There formulas you need from almost any introductory prob- are thus 199 2 = 39,601 pairs of numbers you could use to ability textbook, such as Winkler and Hays (1975). For an test the program. Note that this is before we even start think- excellent introduction, read the first 100 or so pages of ing about what happens ifyou do something complicated, like Feller's An Introduction to Probability Theory and Its pressing <Backspace>. Once editing keys are allowed, the Applications (1950). sky is the limit on the number of possible tests. 7 LOOKING FOR BOUNDARY CONDITIONS Ifyoutest 2 + 3,andthen3 + 4, yourtests aren't exac« repetitions of each other, but they're close. Both ask what happens when you feed the program two one-digit positive numbers. If the program passes either test, you'd expect it to pass the other. Since there are too many possible tests to run, you have to pick test cases that are significant. If you expect the same result from two tests, use only one of them. If you expect the same result from two tests, they belong to the same class. Eighty-one test cases are in the class of "pairs of one-digit positive numbers." Once you realize that you're dealing with a class of test cases, test a few representatives and ignore the rest. There's an important trick to this: When you choose representatives of a class for testing, always pick the ones you think the program is most likely to fail. The best test cases are at the boundaries of a class. Just beyond the boundary, the program's behavior will change. For example, since the program is supposed to handle two-digit numbers, 99 and any number smaller should be OK, but 100 and anything larger are not. The boundary cases for these two classes are 99 and 100. All members of a class of test cases cause the program to behave in essentially the same way. Anything that makes the program change its behavior marks the boundary between two classes. Not every boundary in a program is intentional, and not all intended boundaries arc set correctly. This is what most bugs are—most bugs cause a program to change its behavior when the programmer didn't want or expect it to, or cause the program not to change its behavior when the programmer did expect it to. Not surprisingly, some of the best places to find errors are near boundaries the programmer did intend. When programming a boundary it doesn't take much to accidentally create an incorrect boundary condition. There are no magic formulas for grouping tests into classes or for finding boundaries. You get better at it with experience. If you looked for boundary conditions by reading the code, you'd find some that aren't obvious in normal program use. However, the programmer should have tested anything obvious in the program listing. It's your task to analyze the program from a different point of view than the programmer's. This will help you find classes, boundary conditions, critical tests, and thus errors that she missed. You should classify possible tests according to what you see in the visible behavior of the program. This may lead to a set of tests very different from those suggested by the listings, and that's what you want. A final point to stress is that you shouldn't just test at one side of a boundary. Programmers usually make sure that their code handles values they expect it to handle, but they often forget to look at its treatment of unexpected values (ones outside the boundaries). They miss errors here, that you should not miss. STEP 3: CHECK THE VALID CASES AND SEE WHAT HAPPENS The test series in Figure 1.4 only covers valid values. In your next planning steps, create series like this for invalid values. Another important series would cover edited numbers—numbers you entered, then changed before pressing <Enter>. But first, check Figure 1.4's easy cases. 8 THE FIRST CYCLE OF TESTING STEP 3: CHECK THE VAUD CASES AND SEE WHAT HAPPENS The reason the program is in testing is that it probably doesn 't work. You can waste a lot of time on fancy tests when the real problem is that the program can't add 2 + 3. Here are the test results: • Positive numbers worked fine; so did zero. • None of the tests with negative numbers worked. The computer locked when you entered the second digit. (Locked means that the computer ignores keyboard input; you have to reset the machine to keep working.) You tried -9 + - 9 to see if it accepts single-digit negative numbers, but it locked when you pressed <Enter> after -9. Evidently, the program does not expect negative numbers. STEP 4: Do SOME TESTING "ON THE FLY" No matter how many test cases of how many types you've created, you will run out of formally planned tests. At some later point, you'll stop formally planning and documenting new tests until the next test cycle. You can keep testing. Run new tests as you think of them, without spending much time preparing or explaining the tests. Trust your instincts. Try any test that feels promising, even if it's similar to others that have already been run. In this example, you quickly reached the switch point from formal to informal testing because the program crashed so soon. Something may be fundamentally wrong. If so, the program will be redesigned. Creating new test series now is risky. They may become obsolete with the next version of the program. Rather than gambling away the planning time, try some exploratory tests—whatever comes to mind. Figure 1.5 shows the tests that we would run, the notes we would take in the process, and the results. Always write down what you do and what happens when you run explor- atory tests. As you can see m Figure 1.5, the program is unsound—it locks the computer at the slightest provocation. You are spending more time restarting the computer than you are testing. As you ran into each problem, you wrote a Problem Report. Hand these in and perhaps write a summary memo about them. Your testing of this version of the program may not be "complete," but for now it is finished. 9 STEP 5: SUMMARIZE WHAT YOU KNOW ABOUT THE PROGRAM AND ITS PROBLEMS This is strictly for your own use. It isn't always necessary but it is often useful. To this point, your thinking has been focused. You've concentrated on specific issues, such as coming up with boundary conditions for valid input. Keeping focused will be more difficult later, when you spend more time executing old test series than you spend thinking. You need time to step back from the specific tasks to think generally about the program, its problems, and your testing strategy. You benefit from spending this time by noticing things that you missed before—new boundary conditions, for example. 10 THE FIRST CYCLE OF TESTING STEP 5: SUMMARIZE WHAT YOU KNOW ABOUT THE PROGRAM AND ITS PROBLEMS A good starting activity is to write down a list of points that summarize your thoughts about the program. Here's our list: • The communication style of the program is extremely terse. • The program doesn't deal with negative numbers. The largest sum that it can handle is 198 and the smallest is 0. • The program treats the third character you type (such as the third digit in 100) as if it were an <Enter>. • The program accepts any character as a valid input, until you press <Enter>. • The program doesn't check whether a number was entered before <Enter>. If you don't enter anything, the program uses the last number entered. Assuming that the programmer isn't hopelessly incompetent, there must be a reason for this ugliness. Possibili- ties that come to mind right away are that she might be trying to make the program very small or very fast. F.rror handling code takes memory space. So do titles, error messages, and instructions. There isn't much room for these in a program that must fit into extremely few bytes. Similarly, it takes time to check characters to see if they're valid, it takes time to check the third character to make sure that it really is an <Enter>, it takes time to print messages on the screen, and it takes time to clear a variable before putting a new value (if there is one) into it. You can't tell, from looking at this list of problems, whether the program was stripped to (orpast) its barest essentials in the interest of speed or in the interest of space. You certainly can't tell from the program whether the extreme measures are justified. To find that out, you have to talk with the programmer. Suppose the programmer is coding with space efficiency as a major goal. How might she save space in the program? Most of the visible "tricks" are already in evidence—no error handling code, no error messages, no instructions onscreen, and no code to test the third character entered. Is there any other way to save space in a program? Yes, of course. She can minimize the room needed to store the data. The "data" in this program are the sum and the entered characters. Storage of the sum The valid sums range from -198 to 198. But the program doesn't handle them all. It only handles positive numbers, so its sums run from 0 to 198. If she stores positive numbers only, the programmer can store anything from 0 to 255 in a byte (8 bits). This is a common and convenient unit of storage in computers. If the programmer thought only about positive numbers and wanted to store the sum in the smallest possible space, a byte would be her unit of choice. [...]... programs can have huge numbers of paths, hi 19 76 he described a 10 0-line program that had 10 18 unique paths For comparative purposes, he noted that the universe is only about 4 X 10 17 seconds old Myers described a much simpler program in 19 79 It was just a loop and a few IF statements In most languages, you could write it in 20 lines of code This program has 10 0 trillion paths; a fast tester could test... numbers between -12 7 and 12 7 The program will fail with sums greater than 12 7 Most programs that try to store too large a number in a byte fail in a specific way: any number larger than 12 7 is interpreted as a negative number Maybe that will happen with this program You should pay attention to large sums in the next cycle of tests; 12 7 and 12 8 are the boundary values The test series in Figure 1. 4 already... "well." This chapter debunks some popular testing myths With them out of the way, we can consider some of the difficult questions that testers continue to face throughout their career, such as: * What/s the point of testing? * What distinguishes good testing from poor testing? * How much testing Is enough? * How can you tell when you've done enough? As we see it, testing Is the process of searching for... you can run the "best" tests, you'll postpone testing whole areas of the program, 13 THE SECOND CYCLE OF TESTING STEP 1: BEFORE DOING ANY TESTING, REVIEW THE RESPONSES TO THE PROBLEM REPORTS CAREFULLY TO SEE WHAT NEEDS TO BE DONE, AND WHAT DOESN'T often until it's too late to fix any but the most serious problems In this example, using numbers between -1 and -9 isn't as good as using the ones planned,... bugs? Beizer's (19 90) review estimates the average number of errors in programs released to Testing at 1 to 3 bugs per 10 0 executable statements There are big differences between programmers, but no one's work is error-free Public and private bugs One error per 10 0 statements is an estimate of public bugs, the ones still left in a p rogram after the programmer declares it error-free Beizer (19 84) reported... that passes It Much of Popper's reasoning applies directly to software testing YOU CANT TEST A PROGRAM COMPLETELY What does it mean to test a program completely? It must mean that at the end of testing, there are no undiscovered software errors Whether they've been fixed is a different issue, but all problems must be known and understood 19 YOU CAN'T TEST A PROGRAM COMPLETELY There is a popular belief... further testing you must do to achieve complete testing • Many salespeople believe their software products are fully tested and error-free, and pass on this claim to customers Some testers also believe in the myth of complete testing They suffer for it They feel insecure, frustrated, and guilty because no matter how hard they try, how cleverly they plan, how much time they spend, and how many staff and computers... on a real bug, found during field testing • • • • • • • The system starts in State 1 This is its normal state, and it returns to State 1 as quickly as possible From State 1, it always goes to State 2 From State 2, it can go to State 3 or State 5 From State 3, it can go to State 4 or State 5 From State 4, it can go to States 3, 5, or 6 From State 5, it can go to States 1, 4, or 6 From State 6, it can... reject 0 as a bad character 11 THE FIRST CYCLE OF TESTING STEP 5: SUMMARIZE WHAT YOU KNOW ABOUT THE PROGRAM AND ITS PROBLEMS Storage of the input The only way to catch this error is by testing with 0, the digit with the smallest ASCII code (48) • I f she said less than 47 instead of less than 48,the program would accept / as a digit The only way to catch this error is by testing with /, the nondigit... cases In future chapters (especially 7,8, and 13 ) we discuss good testing strategies INTERESTING READING In an influential book on the philosophy of science, Karl Popper (19 65) argues that the correct approach to testing a scientific theory Is not to try to verify it but to seek to refute the theory—that is, to prove that It has errors The harsher the testing, the more confidence we can have in a theory . THE SOFTWARE DEVELOPMENT PROCESS 29 SOFTWARE ERRORS 61 REPORTING AND ANALYZING BUGS 67 THE PROBLEM TRACKING SYSTEM 89 TEST CASE DESIGN 12 5 TESTING USER MANUALS 14 4 TESTING TOOLS 15 4. 1 Testing Computer Software Cem Kaner Jack Falk Hung Quoc Nguyen 2 CONTENTS AN EXAMPLE TEST SERIES 3 THE OBJECTIVES AND LIMITS OF TESTING 19 TEST TYPES. DOCUMENTATION 16 8 TYING IT TOGETHER 219 MANAGING A TESTING GROUP 267 3 AN EXAMPLE TEST SERIES THE REASON FOR THIS CHAPTER Software testing Is partly intuitive but largely systematic. Good testing

Ngày đăng: 06/08/2014, 09:20

TỪ KHÓA LIÊN QUAN