The art of software testing. Myers (2nd edition) (2004) (811502), страница 13
Текст из файла (страница 13)
Use guideline 2 for each output condition. If an information-retrieval system displays the most relevant abstracts basedon an input request, but never more than four abstracts,write test cases such that the program displays zero, one, andfour abstracts, and write a test case that might cause the program to erroneously display five abstracts.5. If the input or output of a program is an ordered set(a sequential file, for example, or a linear list or a table),focus attention on the first and last elements of the set.6. In addition, use your ingenuity to search for other boundaryconditions.The triangle analysis program of Chapter 1 can illustrate the needfor boundary-value analysis. For the input values to represent a triangle, they must be integers greater than 0 where the sum of any two isgreater than the third.
If you were defining equivalent partitions, youmight define one where this condition is met and another where thesum of two of the integers is not greater than the third. Hence, twopossible test cases might be 3-4-5 and 1-2-4. However, we havemissed a likely error. That is, if an expression in the program wereTest-Case Design61coded as A+B>=C instead of A+B>C, the program would erroneously tellus that 1-2-3 represents a valid scalene triangle. Hence, the importantdifference between boundary-value analysis and equivalence partitioning is that boundary-value analysis explores situations on andaround the edges of the equivalence partitions.As an example of a boundary-value analysis, consider the following program specification:MTEST is a program that grades multiple-choice examinations. Theinput is a data file named OCR, with multiple records that are 80characters long.
Per the file specification, the first record is a title usedas a title on each output report. The next set of records describes thecorrect answers on the exam. These records contain a “2” as the lastcharacter. In the first record of this set, the number of questions islisted in columns 1–3 (a value of 1–999). Columns 10–59 contain thecorrect answers for questions 1–50 (any character is valid as ananswer).
Subsequent records contain, in columns 10–59, the correctanswers for questions 51–100, 100–150, and so on.The third set of records describes the answers of each student;each of these records contains a “3” in column 80. For each student,the first record contains the student’s name or number in columns1–9 (any characters); columns 10–59 contain the student’s answersfor questions 1–50. If the test has more than 50 questions,subsequent records for the student contain answers 51–100,101–150, and so on, in columns 10–59. The maximum number ofstudents is 200.
The input data are illustrated in Figure 4.4. The fouroutput records are1. A report, sorted by student identifier, showing each student’sgrade (percentage of answers correct) and rank.2. A similar report, but sorted by grade.3. A report indicating the mean, median, and standard deviation ofthe grades.4. A report, ordered by question number, showing the percentageof students answering each question correctly.(End of specification.)62The Art of Software TestingFigure 4.4Input to the MTEST program.Title180No. ofquestions1Correct answers 1–503 49 10259 60Correct answers 51–10019 10Student identifier1259 60Correct answers 1–509 1059 609 10Student identifier179 80359 60Correct answers 1–509 1079 803Correct answers 51–100179 8079 80359 6079 80We can begin by methodically reading the specification, lookingfor input conditions. The first boundary input condition is an emptyinput file.
The second input condition is the title record; boundaryconditions are a missing title record and the shortest and longest possible titles. The next input conditions are the presence of correctanswer records and the number-of-questions field on the first answerTest-Case Design63record. The equivalence class for the number of questions is not1–999, since something special happens at each multiple of 50 (i.e.,multiple records are needed).
A reasonable partitioning of this intoequivalence classes is 1–50 and 51–999. Hence, we need test caseswhere the number-of-questions field is set to 0, 1, 50, 51, and 999.This covers most of the boundary conditions for the number ofcorrect-answer records; however, three more interesting situations arethe absence of answer records and having one too many and one toofew answer records (for example, the number of questions is 60, butthere are three answer records in one case and one answer record inthe other case).
The test cases identified so far are1. Empty input file.2. Missing title record.3. 1-character title.4. 80-character title.5. 1-question exam.6. 50-question exam.7. 51-question exam.8. 999-question exam.9. 0-question exam.10. Number-of-questions field has nonnumeric value.11. No correct-answer records after title record.12. One too many correct-answer records.13.
One too few correct-answer records.The next input conditions are related to the students’ answers. Theboundary-value test cases here appear to be14. 0 students.15. 1 student.16. 200 students.17. 201 students.18. A student has one answer record, but there are two correctanswer records.19. The above student is the first student in the file.64The Art of Software Testing20. The above student is the last student in the file.21. A student has two answer records, but there is just onecorrect-answer record.22.
The above student is the first student in the file.23. The above student is the last student in the file.You also can derive a useful set of test cases by examining the output boundaries, although some of the output boundaries (e.g., emptyreport 1) are covered by the existing test cases. The boundary conditions of reports 1 and 2 are0 students (same as test 14).1 student (same as test 15).200 students (same as test 16).24.
All students receive the same grade.25. All students receive a different grade.26. Some, but not all, students receive the same grade (to see ifranks are computed correctly).27. A student receives a grade of 0.28. A student receives a grade of 100.29. A student has the lowest possible identifier value (to checkthe sort).30. A student has the highest possible identifier value.31. The number of students is such that the report is just largeenough to fit on one page (to see if an extraneous page isprinted).32. The number of students is such that all students but one fiton one page.The boundary conditions from report 3 (mean, median, and standard deviation) are33.
The mean is at its maximum (all students have a perfectscore).34. The mean is 0 (all students receive a grade of 0).Test-Case Design6535. The standard deviation is at its maximum (one studentreceives a 0 and the other receives a 100).36. The standard deviation is 0 (all students receive the samegrade).Tests 33 and 34 also cover the boundaries of the median.
Anotheruseful test case is the situation where there are 0 students (looking fora division by 0 in computing the mean), but this is identical to testcase 14.An examination of report 4 yields the following boundary-valuetests:37. All students answer question 1 correctly.38. All students answer question 1 incorrectly.39. All students answer the last question correctly.40. All students answer the last question incorrectly.41. The number of questions is such that the report is just largeenough to fit on one page.42.
The number of questions is such that all questions but one fiton one page.An experienced programmer would probably agree at this point thatmany of these 42 test cases represent common errors that might havebeen made in developing this program, yet most of these errors probably would go undetected if a random or ad hoc test-case-generationmethod were used. Boundary-value analysis, if practiced correctly, isone of the most useful test-case-design methods. However, it often isused ineffectively because the technique, on the surface, sounds simple.You should understand that boundary conditions may be very subtleand, hence, identification of them requires a lot of thought.Cause-Effect GraphingOne weakness of boundary-value analysis and equivalence partitioning is that they do not explore combinations of input circumstances.
For66The Art of Software Testinginstance, perhaps the MTEST program of the previous section fails ifthe product of the number of questions and the number of studentsexceeds some limit (the program runs out of memory, for example).Boundary-value testing would not necessarily detect such an error.The testing of input combinations is not a simple task becauseeven if you equivalence-partition the input conditions, the numberof combinations usually is astronomical. If you have no systematicway of selecting a subset of input conditions, you’ll probably select anarbitrary subset of conditions, which could lead to an ineffective test.Cause-effect graphing aids in selecting, in a systematic way, a highyield set of test cases.
It has a beneficial side effect in pointing outincompleteness and ambiguities in the specification.A cause-effect graph is a formal language into which a naturallanguage specification is translated. The graph actually is a digitallogic circuit (a combinatorial logic network), but instead of standardelectronics notation, a somewhat simpler notation is used. No knowledge of electronics is necessary other than an understanding of Boolean logic (understanding the logic operators and, or, and not).The following process is used to derive test cases:1. The specification is divided into workable pieces.