Prac02 Testing 08 02 - tut work PDF

Title Prac02 Testing 08 02 - tut work
Course Intermediate Object-Oriented Programming
Institution La Trobe University
Pages 7
File Size 132.5 KB
File Type PDF
Total Downloads 370
Total Views 438

Summary

Intermediate Object-Oriented Programming Practice Class 2 (Week 3) Introduction to Program Testing • Program testing is the process of running a program to identify the differences, if any, between the expected and actual results. • Approaches to testing are generally classified into black-box testi...


Description

Intermediate Object-Oriented Programming Practice Class 2 (Week 3)

Introduction to Program Testing • Program testing is the process of running a program to identify the differences, if any, between the expected and actual results. • Approaches to testing are generally classified into black-box testing and white-box testing • In black-box testing, the way we design test cases is based on the of the program/system/app (also known as the functional requirements of the program/system/app). • In contrast, white-box testing examines the to design test cases .

and uses that structure as a basis

• In this subject, we consider (only) the basic techniques of black-box and white-box testing.

1

Black-box Testing

Several commonly used black-box testing techniques are based on the concept of equivalence partitioning.

Equivalence partitioning (EP) In equivalence partitioning, the possible values of input data are divided into several classes, called equivalence classes. Some of these equivalence classes represent valid data and some invalid data. e.g. A program reads an value for variable . A valid value must be between 0 and 23 inclusive. In this case, we have three equivalence classes: Equivalence class EC1 EC2 EC3

Range of values 0 ≤ hours ≤ 23 hours < 0 hours > 23

Valid/Invalid? valid invalid invalid

Representative test values Once we have the equivalence class, the next step is to select classes. One way to select test values is to select

from those equivalence

value from an equivalence class and regard it a

of the class.

1

e.g. Continuing with the previous example, we may choose the representative test values shown in the table below (Note that the selection of representative values can be quite arbitrary): Equivalence class

Range of values

Valid?

EC1 EC2 EC3

0 ≤ hours ≤ 23 hours < 0 hours > 23

valid invalid invalid

Value selected for testing 12 -10 30

The above selection of test value for the example leads to the following three test cases: Test case TC1 TC2 TC3

Input value 12 -10 30

Expected result input is recognized as valid input is rejected as invalid input is rejected as invalid

Boundary test values Another way to select test values from equivalence classes is to use the boundary values. Boundary values are useful for testing because more errors are usually discovered at the boundary of input value ranges than in the middle. Taking this selection approach, we obtain the test values shown in the table below: Equivalence class EC1 EC2 EC3

Range of values 0 ≤ hours ≤ 23 hours < 0 hours > 23

Valid? valid invalid invalid

Boundary valued 0, 23 -1 24

Using those test values, we have four test cases Test case TC1 TC2 TC3 TC4

Input value 0 23 -1 24

Expected result input is recognized as valid input is recognized as valid input is rejected as invalid input is rejected as invalid

2

Designing test cases for two or more variables Consider the program which takes inputs for • variable

, whose valid values are between 0 and 23 inclusive, and

• variable

, whose valid values are between 0 and 59 inclusive.

The equivalence classes and their boundary values are as shown below: Equivalence class H1 H2 H3 Equivalence class M1 M2 M3

Now, each

Range of values 0 ≤ hours ≤ 23 hours < 0 hours > 23 Range of values 0 ≤ minutes ≤ 59 minutes < 0 minutes > 59

Valid? valid invalid invalid Valid? valid invalid invalid

will be made up of a

Boundary valued 0, 23 -1 24 Boundary valued 0, 59 -1 60

for

and

.

How do we construct these pairs? A common way is to apply the following two techniques:

Test cases for valid test values: Each valid test value should appear in at least one test case in which the test values for other input variables are also valid.

Test cases for invalid test values: Each in valid test value should appear in at least one test case in which the test values for other input variables are valid.

e.g. (Continue) • We have two boundary values for (h1 = 0, h2= 23) and two for (m1 = 0, m2 = 59). Each valid test value should appear in a test case where the other test value is also valid. To achieve this, we can simply have the following combinations: • h1 and m1 • h2 and m2 These combinations give us the following test cases Test case TC1 TC2

hours 0 23

minutes 0 59

3

Expected result accepted accepted

• Test cases for invalid test values. We have four invalid boundary test values: two for hours (-1, 24) and two for minutes (-1, 60). Each invalid test value should appear in a test case where the other test value is valid. To achieve this, we can start with a in which both inputs are valid. For example, we can choose the following (which uses some typical values of the equivalence classes): hours 12

minutes 30

We then consider each value in turn and substitute it into the chosen base test case above. The first invalid test value for is -1. Replacing 12 by -1 we get a test case with and . Repeating this kind of substitution for other invalid test values, we could get test cases shown below: Test case TC3 TC4 TC5 TC6

hours -1 24 12 12

minutes 30 30 -1 60

4

Expected result rejected rejected rejected rejected

Question 1 Consider the following problem:

Suppose we have a method that determines if a fun park patron is allowed to purchase a ticket to ride The method takes two integer arguments • The age of the patron in years • The height of the patron in cm and returns • true if the patron is allowed to ride the Underworld Accelerator • false if the patron is not allowed to ride the Underworld Accelerator Thus, we have two input variables for the program: • age = the age of the patron in years • height = the height of the patron in cm Task 1: Determine the valid and invalid equivalence classes (ECs) for each input (age and height), and their boundary values. Equivalence class

Range of values

Valid/Invalid

Boundary values

Equivalence class

Range of values

Valid/Invalid

Boundary values

Task 2: Using the test values selected in Task 1 above, construct black-box test cases. (Each test case has a value for and a value for .) Test Case TC1 TC2

age

height

5

Expected result

2

White-box Testing

White-box testing uses the program structure as a basis to design test cases . There are numerous white-box testing techniques. In this subject, we will restrict ourselves to the following strategies:

S1. For selection statement, choose tests (i.e. test cases) that will execute each branch at least once S2. For repetition statement, Choose tests that will result in the execution of the body of statement no times, once, multiple, and the maximum number of times (if each is possible) S3. For conjunction condition (containing subconditions connected by the AND operator), choose tests where 1. all the subconditions are true 2. all subconditions are true, except one (if possible) S4. For disjunction condition (containing subconditions connected by the OR operator), choose tests where 1. all the subconditions are false 2. all subsconditions are false, except one (if possible)

Question 2 Consider the following code segment

You are required to apply white-box testing to the above code segment. a.

Which of the four strategies (S1-S4) are relevant?

b.

Devise test cases for each of the relevant strategies.

6

3

Notes on Testing The Program’s Robustness – Bizarre Inputs

In addition to the testing techniques presented above, if we want to test the robustness of our program, then we should also consider what we call “bizarre inputs”. Again, consider the Underworld Accelerator problem. Suppose the input data are initially received as strings of characters (entered by the user) and then those strings are converted into values. In that situation, it is possible for an input to be entirely inappropriate. For example, the user may enter the string or an (by hitting the Enter key). How to treat bizarre inputs • We can view such unsuitable inputs as bizarre and regard them as members of . • Those values can be treated in the same way as the

values we considered earlier.

• That is, we use a base valid test case, and for each bizarre value, we make a substitution to form a test case. 

7...


Similar Free PDFs