29
Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random Boundary Value Testing Mohammad Mousavi Eindhoven University of Technology, The Netherlands Software Testing, 2012 Mousavi: Boundary Value Testing

Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value Testing

Mohammad Mousavi

Eindhoven University of Technology, The Netherlands

Software Testing, 2012

Mousavi: Boundary Value Testing

Page 2: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Announcements

I Groups are announce on the web page.

Mousavi: Boundary Value Testing

Page 3: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Outline

Introduction

Robustness

Worst-Cases

Worst-Cases + Robustness

Special Values

Random

Mousavi: Boundary Value Testing

Page 4: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Assumptions

I functional testing: program is an input from a certain domainto a certain range

I impossible to check all input/output combinations: need tochoose some

I applicability: domain comprises (product of)

1. independent values2. physical (not logical) quantities (ordered, in an interval, taking

all values in the interval)

I rationale: most errors occur at extremes (< instead of <=,counters off by one)also called: stress testing

I technique also applicable to range boundaries

Mousavi: Boundary Value Testing

Page 5: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Idea

I Choose 4 candidate values for each input inthe range [a, b]:

1. at the 2 extremes (a and b),2. near the 2 extremes (predecessor of a and

successor of b).

I Choose nominal values for all other variables.

I Single-fault assumption: each failure is theresult of a single bug (and a single error)

I Assuming n input variables, 4n + 1test-cases.

Mousavi: Boundary Value Testing

Page 6: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Functional Testing: Mortgage Example

Spec. Write a program that takesthree inputs: gender (boolean), age([18-55]), salary ([0-10000])and output the total mortgage for one person

Mortgage = salary * factor,where factor is given by the following table.

Category Male FemaleYoung (18-35 years) 75 (18-30 years) 70Middle (36-45 years) 55 (31-40 years) 50Old (46-55 years) 30 (41-50 years) 35

Mousavi: Boundary Value Testing

Page 7: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

An Implementation

Mortgage (male:Boolean, age:Integer, salary:Integer): Integerif male thenreturn ((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age <40)?(55 ∗ salary) : (30 ∗ salary))

else {female}return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age <40)?(50 ∗ salary) : (35 ∗ salary))

end if

Mousavi: Boundary Value Testing

Page 8: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value TestingMortgage (male:Boolean, age:Integer, salary:Integer): Integerif male thenreturn ((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age <40)?(55 ∗ salary) : (30 ∗ salary))

else {female}return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age <40)?(50 ∗ salary) : (35 ∗ salary))

end if

I age: extremes: 18, 55(?). near extremes: 19, 54. nominal: 25.I salary: extremes: 0, 10000. near extremes: 1, 9999. nominal:

5000.I male: ??

true, false. nominal: true. (just to try the technique)

No boundaries: define artificial boundaries (e.g., 0 and MAXINTfor integers).

Mousavi: Boundary Value Testing

Page 9: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value TestingMortgage (male:Boolean, age:Integer, salary:Integer): Integerif male thenreturn ((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age <40)?(55 ∗ salary) : (30 ∗ salary))

else {female}return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age <40)?(50 ∗ salary) : (35 ∗ salary))

end if

I age: extremes: 18, 55(?). near extremes: 19, 54. nominal: 25.I salary: extremes: 0, 10000. near extremes: 1, 9999. nominal:

5000.I male:

?? true, false. nominal: true. (just to try the technique)

No boundaries: define artificial boundaries (e.g., 0 and MAXINTfor integers).

Mousavi: Boundary Value Testing

Page 10: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value TestingMortgage (male:Boolean, age:Integer, salary:Integer): Integerif male thenreturn ((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age <40)?(55 ∗ salary) : (30 ∗ salary))

else {female}return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age <40)?(50 ∗ salary) : (35 ∗ salary))

end if

I age: extremes: 18, 55(?). near extremes: 19, 54. nominal: 25.I salary: extremes: 0, 10000. near extremes: 1, 9999. nominal:

5000.I male:

??

true, false. nominal: true. (just to try the technique)

No boundaries: define artificial boundaries (e.g., 0 and MAXINTfor integers).

Mousavi: Boundary Value Testing

Page 11: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value Testing

if (male) then return((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age < 40)?(55 ∗ salary) : (30 ∗ salary))

else return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age < 40)?(50 ∗ salary) : (35 ∗ salary))

Gender Age Salary Output Correct Out. Pass/Failmale 18 5000 75*5000 75*5000 Pmale 19 5000 75*5000 75*5000 Pmale 25 5000 75*5000 75*5000 Pmale 54 5000 30*5000 30*5000 Pmale 55 5000 30*5000 30*5000 Pmale 25 0 75*0 75*0 Pmale 25 1 75*1 75*1 Pmale 25 9999 75*9999 75*9999 Pmale 25 10000 75*9999 75*10000 Pfemale 25 5000 75*5000 70*5000 F

Mousavi: Boundary Value Testing

Page 12: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value Testing

Observations

I strange technique for booleans: decision-table-basedtechnique (yet to come)

I not suitable due to the dependency between age and gender

I more combinations to be tested: wait for a few slides!

I finer partitioning needed: wait till next session

I exploiting more information from the code

Mousavi: Boundary Value Testing

Page 13: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Outline

Introduction

Robustness

Worst-Cases

Worst-Cases + Robustness

Special Values

Random

Mousavi: Boundary Value Testing

Page 14: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Idea

I In addition to the 4 candidates,choose 2 more candidates justbeyond the extremes

I Predicting the output: tricky

I Suitable for PL’s with weak typing(testing exception handling)

I Assuming n input variables, 6n + 1test-cases.

Mousavi: Boundary Value Testing

Page 15: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Robustness BV Testing: Example

if (male) then return((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age < 40)?(55 ∗ salary) : (30 ∗ salary))

else return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age < 40)?(50 ∗ salary) : (35 ∗ salary))

Gender Age Salary Output Correct Out. Pass/Failmale 17 5000 30*5000 nog even niet Fmale 56 5000 75*5000 too late Fmale 25 -1 75*-1 invalid salary Fmale 25 10001 75*10001 75*10000(?) F

Mousavi: Boundary Value Testing

Page 16: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Outline

Introduction

Robustness

Worst-Cases

Worst-Cases + Robustness

Special Values

Random

Mousavi: Boundary Value Testing

Page 17: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Idea

I multiple-fault assumption: a fault maybe the result of a combination of errors

I all combinations of 5 values for allvariables

I 5n test-cases

Mousavi: Boundary Value Testing

Page 18: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Worst-Case BV Testing

if (male) then return((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age < 40)?(55 ∗ salary) : (30 ∗ salary))

else return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age < 40)?(50 ∗ salary) : (35 ∗ salary))

50 cases (5 * 5 * 2) in total;discovered fault are quite similar to Robustness BV Testing (due tothe same bugs)(single-fault: reasonable in this case)

Mousavi: Boundary Value Testing

Page 19: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Outline

Introduction

Robustness

Worst-Cases

Worst-Cases + Robustness

Special Values

Random

Mousavi: Boundary Value Testing

Page 20: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Idea

I combination of worst case androbustness BV Testing

I all combinations of 7 values for allvariables

I 7n test-cases

Mousavi: Boundary Value Testing

Page 21: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Boundary Value Testing

if (male) then return((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age < 40)?(55 ∗ salary) : (30 ∗ salary))

else return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age < 40)?(50 ∗ salary) : (35 ∗ salary))

98 cases (7 * 7 * 2) in total;

Mousavi: Boundary Value Testing

Page 22: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

A Brief Comparison

Mousavi: Boundary Value Testing

Page 23: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Outline

Introduction

Robustness

Worst-Cases

Worst-Cases + Robustness

Special Values

Random

Mousavi: Boundary Value Testing

Page 24: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Special Value Testing: Idea

I using domain knowledge

I finding corresponding boundaries for internal variables

I in combination with the techniques mentioned before

Mousavi: Boundary Value Testing

Page 25: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Special Value Testing: Example

if (male) then return((18 ≤ age < 35)?(75 ∗ salary) : (31 ≤ age < 40)?(55 ∗ salary) : (30 ∗ salary))

else return ((18 ≤ age < 30)?(75 ∗ salary) : (31 ≤ age < 40)?(50 ∗ salary) : (35 ∗ salary))

In addition to some of the worst-case robustness test-cases:

Gender Age Salary Output Correct Out. Pass/Failmale 18 1 75*1 75*1 Pmale 35 1 55*1 75*1 Fmale 36 1 55*1 55*1 Pmale 45 1 30*1 55*1 Fmale 46 1 30*1 30*1 Pmale 55 1 30*1 30*1 P

Mousavi: Boundary Value Testing

Page 26: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Special Value Testing: Example (Cont’d)

Test-cases (cont’d):

Gender Age Salary Output Correct Out. Pass/Failfemale 18 1 75*1 70*1 Ffemale 30 1 35*1 70*1 Ffemale 31 1 50*1 50*1 Pfemale 40 1 35*1 50*1 Ffemale 41 1 35*1 35*1 Pfemale 50 1 35*1 35*1 P

Mousavi: Boundary Value Testing

Page 27: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Outline

Introduction

Robustness

Worst-Cases

Worst-Cases + Robustness

Special Values

Random

Mousavi: Boundary Value Testing

Page 28: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Random Testing

I randomly choosing input!

I range boundaries: determining the effectiveness of thetest-cases

I statistical techniques

Mousavi: Boundary Value Testing

Page 29: Boundary Value Testing - University of KansasIntroductionRobustnessWorst-CasesWorst-Cases + RobustnessSpecial ValuesRandom Assumptions I functional testing: program is an input from

Introduction Robustness Worst-Cases Worst-Cases + Robustness Special Values Random

Conclusions

Boundary-Value Testing:

+ relatively straightforward test-case generation

- no sense of covering the input domain

- not enough white-box information exploited (apart fromspecial-value testing)

Particularly suitable when the input data are:

1. independent

2. physical measures

Mousavi: Boundary Value Testing