CSC 309 Lecture Notes Week 4 Formal Specs in Testing Intro to - - PowerPoint PPT Presentation

csc 309 lecture notes week 4 formal specs in testing
SMART_READER_LITE
LIVE PREVIEW

CSC 309 Lecture Notes Week 4 Formal Specs in Testing Intro to - - PowerPoint PPT Presentation

CSC309-S15-L4 Slide 1 CSC 309 Lecture Notes Week 4 Formal Specs in Testing Intro to Testing Techniques CSC309-S15-L4 Slide 2 I. Deriving and refining method specs. A. Testing requires that we know exactly what constitutes valid versus


slide-1
SLIDE 1

CSC309-S15-L4 Slide 1

CSC 309 Lecture Notes Week 4 Formal Specs in Testing Intro to Testing Techniques

slide-2
SLIDE 2

CSC309-S15-L4 Slide 2

  • I. Deriving and refining method specs.
  • A. Testing requires that we know exactly what

constitutes valid versus invalid inputs.

  • 1. Pre- and postconds answer this question.
  • 2. Used to inform unit test development.
slide-3
SLIDE 3

CSC309-S15-L4 Slide 3

Overview, cont’d

  • B. Recap of what pre/postconds mean.
  • 1. Precondition is one boolean expression

that is true before method executes.

  • 2. Postcondition is one boolean expression

that is true after method completes.

slide-4
SLIDE 4

CSC309-S15-L4 Slide 4

  • II. Formal specs used in testing
  • A. Formal method test consists of:
  • 1. Inputs within legal ranges, expected output
  • 2. Inputs outside legal ranges, expected output
  • 3. Inputs on boundaries, expected output
slide-5
SLIDE 5

CSC309-S15-L4 Slide 5

Formal specs in testing, cont’d

  • B. Preconds used to determine inputs.
  • C. Postconds used to determine expected output
slide-6
SLIDE 6

CSC309-S15-L4 Slide 6

  • III. Formal specs in formal verification
  • A. To verify formally, two specs needed:
  • 1. formal spec of given program
  • 2. formal spec of programming language
slide-7
SLIDE 7

CSC309-S15-L4 Slide 7

Formal specs in verification, cont’d

  • B. Program spec is "entry ticket" to verification.
  • C. Details in later lectures.
slide-8
SLIDE 8

CSC309-S15-L4 Slide 8

  • IV. Precondition enforcement -- "by contract"

versus "defensive programming"

  • A. Precond failure means an op is "undefined".
  • 1. For abstract spec, this is enough.
  • 2. At imple’n level, precond must be dealt

with more concretely.

  • 3. Tw
  • basic approaches.
slide-9
SLIDE 9

CSC309-S15-L4 Slide 9

Precond enforcement, cont’d

  • B. Approach 1: Precond is guaranteed true,

before method call.

  • 1. This is "programming by contract".
  • 2. Precond enforced by callers.
  • 3. Verified or checked at calling site.
  • 4. Bottom line -- called method assumes its

precond is always true.

slide-10
SLIDE 10

CSC309-S15-L4 Slide 10

Precond enforcement, cont’d

  • C. Approach 2: Precond is checked by

method being called.

  • 1. This is "Defensive programming".
  • 2. Method includes logic to enforce its own

precondition.

  • 3. Enforcement can:
slide-11
SLIDE 11

CSC309-S15-L4 Slide 11

Precond enforcement, cont’d

  • a. Assert unconditional failure.
  • b. Return "null" value.
  • c. Output error report.
  • d. Throw an exception.
slide-12
SLIDE 12

CSC309-S15-L4 Slide 12

Precond enforcement, cont’d

  • D. In Model/View comm’n, we use exception

handling approach.

  • E. We will discuss exception handling further in

upcoming lectures.

slide-13
SLIDE 13

CSC309-S15-L4 Slide 13

  • V. Details of deriving method specs.
  • A. Start with Spest specs for 308.
  • B. Update and expand based on design refine-

ments done in 309.

  • C. For some details, see M3 example.
slide-14
SLIDE 14

CSC309-S15-L4 Slide 14

Now on to General System Testing Techniques

slide-15
SLIDE 15

CSC309-S15-L4 Slide 15

  • VI. General Concepts
slide-16
SLIDE 16

CSC309-S15-L4 Slide 16

  • VI. General Concepts
  • A. Components are independently testable.
slide-17
SLIDE 17

CSC309-S15-L4 Slide 17

  • VI. General Concepts
  • A. Components are independently testable.
  • B. Testing is thorough and systematic.
slide-18
SLIDE 18

CSC309-S15-L4 Slide 18

  • VI. General Concepts
  • A. Components are independently testable.
  • B. Testing is thorough and systematic.
  • C. Testing is repeatable.
slide-19
SLIDE 19

CSC309-S15-L4 Slide 19

  • VII. Overall system testing styles
slide-20
SLIDE 20

CSC309-S15-L4 Slide 20

  • VII. Overall system testing styles
  • A. Top-down
slide-21
SLIDE 21

CSC309-S15-L4 Slide 21

  • VII. Overall system testing styles
  • A. Top-down
  • 1. Top-level methods tested first.
slide-22
SLIDE 22

CSC309-S15-L4 Slide 22

  • VII. Overall system testing styles
  • A. Top-down
  • 1. Top-level methods tested first.
  • 2. "Stubs" written for lower-level methods.
slide-23
SLIDE 23

CSC309-S15-L4 Slide 23

Testing styles, cont’d

  • B. Bottom-up
slide-24
SLIDE 24

CSC309-S15-L4 Slide 24

Testing styles, cont’d

  • B. Bottom-up
  • 1. Lower-level methods tested first.
slide-25
SLIDE 25

CSC309-S15-L4 Slide 25

Testing styles, cont’d

  • B. Bottom-up
  • 1. Lower-level methods tested first.
  • 2. Function "drivers" written for upper-level

methods.

slide-26
SLIDE 26

CSC309-S15-L4 Slide 26

Testing styles, cont’d

  • C. Object-oriented
slide-27
SLIDE 27

CSC309-S15-L4 Slide 27

Testing styles, cont’d

  • C. Object-oriented
  • 1. Methods for particular class are tested.
slide-28
SLIDE 28

CSC309-S15-L4 Slide 28

Testing styles, cont’d

  • C. Object-oriented
  • 1. Methods for particular class are tested.
  • 2. Stubs and drivers written as necessary.
slide-29
SLIDE 29

CSC309-S15-L4 Slide 29

Testing styles, cont’d

  • D. Hybrid
slide-30
SLIDE 30

CSC309-S15-L4 Slide 30

Testing styles, cont’d

  • D. Hybrid
  • 1. A combination of top-down, bottom-up,

and object-oriented testing is employed.

slide-31
SLIDE 31

CSC309-S15-L4 Slide 31

Testing styles, cont’d

  • D. Hybrid
  • 1. A combination of top-down, bottom-up,

and object-oriented testing is employed.

  • 2. This is a good practical approach.
slide-32
SLIDE 32

CSC309-S15-L4 Slide 32

Testing styles, cont’d

  • E. Big-bang
slide-33
SLIDE 33

CSC309-S15-L4 Slide 33

Testing styles, cont’d

  • E. Big-bang
  • 1. All compiled in one huge executable.
slide-34
SLIDE 34

CSC309-S15-L4 Slide 34

Testing styles, cont’d

  • E. Big-bang
  • 1. All compiled in one huge executable.
  • 2. Cross fingers and run it.
slide-35
SLIDE 35

CSC309-S15-L4 Slide 35

Testing styles, cont’d

  • E. Big-bang
  • 1. All compiled in one huge executable.
  • 2. Cross fingers and run it.
  • 3. When big bang fizzles,

enter debugger and hack.

slide-36
SLIDE 36

CSC309-S15-L4 Slide 36

  • VIII. Independently testable designs
  • A. Modular interfaces designed thoroughly.
  • 1. Don’t fudge on method signatures,

pre/post logic.

  • 2. Be clear on public and protected.
slide-37
SLIDE 37

CSC309-S15-L4 Slide 37

Independently testable designs, cont’d

  • B. Write stubs and drivers as necessary.
slide-38
SLIDE 38

CSC309-S15-L4 Slide 38

Independently testable designs, cont’d

  • B. Write stubs and drivers as necessary.
  • 1. A stub is also known as a mock.
slide-39
SLIDE 39

CSC309-S15-L4 Slide 39

Independently testable designs, cont’d

  • B. Write stubs and drivers as necessary.
  • 1. A stub is also known as a mock.
  • 2. Drivers generally supplied by testing

framework, as part of its typical use.

slide-40
SLIDE 40

CSC309-S15-L4 Slide 40

  • IX. General approaches to testing
slide-41
SLIDE 41

CSC309-S15-L4 Slide 41

  • IX. General approaches to testing
  • A. Black box testing
slide-42
SLIDE 42

CSC309-S15-L4 Slide 42

  • IX. General approaches to testing
  • A. Black box testing
  • 1. Each method viewed as black box.
slide-43
SLIDE 43

CSC309-S15-L4 Slide 43

  • IX. General approaches to testing
  • A. Black box testing
  • 1. Each method viewed as black box.
  • 2. Function tested using spec only.
slide-44
SLIDE 44

CSC309-S15-L4 Slide 44

General approaches, cont’d

  • B. White-box testing
slide-45
SLIDE 45

CSC309-S15-L4 Slide 45

General approaches, cont’d

  • B. White-box testing
  • 1. Testing based on method code.
slide-46
SLIDE 46

CSC309-S15-L4 Slide 46

General approaches, cont’d

  • B. White-box testing
  • 1. Testing based on method code.
  • 2. Inputs that fully exercise code logic.
slide-47
SLIDE 47

CSC309-S15-L4 Slide 47

General approaches, cont’d

  • B. White-box testing
  • 1. Testing based on method code.
  • 2. Inputs that fully exercise code logic.
  • 3. Each control path is exercised at least
  • nce by some test.
slide-48
SLIDE 48

CSC309-S15-L4 Slide 48

General approaches, cont’d

  • C. Runtime pre/postcond enforcement
slide-49
SLIDE 49

CSC309-S15-L4 Slide 49

General approaches, cont’d

  • C. Runtime pre/postcond enforcement
  • 1. Code added to methods to enforce

pre/postconds at runtime.

slide-50
SLIDE 50

CSC309-S15-L4 Slide 50

General approaches, cont’d

  • C. Runtime pre/postcond enforcement
  • 1. Code added to methods to enforce

pre/postconds at runtime.

  • 2. E.g., input range checking.
slide-51
SLIDE 51

CSC309-S15-L4 Slide 51

General approaches, cont’d

  • C. Runtime pre/postcond enforcement
  • 1. Code added to methods to enforce

pre/postconds at runtime.

  • 2. E.g., input range checking.
  • 3. Function returns (or throws) error if con-

dition is not met.

slide-52
SLIDE 52

CSC309-S15-L4 Slide 52

General approaches, cont’d

  • C. Runtime pre/postcond enforcement
  • 1. Code added to methods to enforce

pre/postconds at runtime.

  • 2. E.g., input range checking.
  • 3. Function returns (or throws) error if con-

dition is not met.

  • 4. Crudely, function could use assert.
slide-53
SLIDE 53

CSC309-S15-L4 Slide 53

General approaches, cont’d

  • D. Formal verification
slide-54
SLIDE 54

CSC309-S15-L4 Slide 54

General approaches, cont’d

  • D. Formal verification
  • 1. Pre/post conds treated as math’l theorems.
slide-55
SLIDE 55

CSC309-S15-L4 Slide 55

General approaches, cont’d

  • D. Formal verification
  • 1. Pre/post conds treated as math’l theorems.
  • 2. Function body treated as math’l formula.
slide-56
SLIDE 56

CSC309-S15-L4 Slide 56

General approaches, cont’d

  • D. Formal verification
  • 1. Pre/post conds treated as math’l theorems.
  • 2. Function body treated as math’l formula.
  • 3. Verification entails proving precond

implies postcond, through method body.

slide-57
SLIDE 57

CSC309-S15-L4 Slide 57

  • X. Functional unit test details
slide-58
SLIDE 58

CSC309-S15-L4 Slide 58

  • X. Functional unit test details
  • A. List of test cases produced for each method.
slide-59
SLIDE 59

CSC309-S15-L4 Slide 59

  • X. Functional unit test details
  • A. List of test cases produced for each method.
  • B. This constitutes the unit test plan.
slide-60
SLIDE 60

CSC309-S15-L4 Slide 60

Case No. Inputs Expected Output Remarks 1 parm 1 = ... ref parm 1 = ... ... ... parm m = ... ref parm n = ... data field a = ... data field a = ... ... ... data field z = ... data field z = ... return = ... throw = ... ... n parm 1 = ... ref parm 1 = ... ... ... parm m = ... ref parm n = ... data field a = ... data field a = ... ... ... data field z = ... data field z = ... return = ... throw = ... ...

slide-61
SLIDE 61

CSC309-S15-L4 Slide 61

Unit test details, cont’d

  • C. Note that
slide-62
SLIDE 62

CSC309-S15-L4 Slide 62

Unit test details, cont’d

  • C. Note that
  • 1. Must specify all input parameters and

data fields.

slide-63
SLIDE 63

CSC309-S15-L4 Slide 63

Unit test details, cont’d

  • C. Note that
  • 1. Must specify all input parameters and

data fields.

  • 2. Must specify all ref parms, return val,

modified fields.

slide-64
SLIDE 64

CSC309-S15-L4 Slide 64

Unit test details, cont’d

  • C. Note that
  • 1. Must specify all input parameters and

data fields.

  • 2. Must specify all ref parms, return val,

modified fields.

  • 3. Not mentioned assumed "don’t care".
slide-65
SLIDE 65

CSC309-S15-L4 Slide 65

Unit test details, cont’d

  • D. One test plan for each method.
slide-66
SLIDE 66

CSC309-S15-L4 Slide 66

Unit test details, cont’d

  • D. One test plan for each method.
  • E. Unit test plans included a javadoc comments.
slide-67
SLIDE 67

CSC309-S15-L4 Slide 67

  • XI. Module, i.e., class testing
slide-68
SLIDE 68

CSC309-S15-L4 Slide 68

  • XI. Module, i.e., class testing
  • A. Write unit test plans for each method.
slide-69
SLIDE 69

CSC309-S15-L4 Slide 69

  • XI. Module, i.e., class testing
  • A. Write unit test plans for each method.
  • B. For class as whole, write class test plan.
slide-70
SLIDE 70

CSC309-S15-L4 Slide 70

  • XI. Module, i.e., class testing
  • A. Write unit test plans for each method.
  • B. For class as whole, write class test plan.
  • C. Guidelines:
slide-71
SLIDE 71

CSC309-S15-L4 Slide 71

Class testing, cont’d

  • 1. Start with unit tests for constructors.
slide-72
SLIDE 72

CSC309-S15-L4 Slide 72

Class testing, cont’d

  • 1. Start with unit tests for constructors.
  • 2. Next, unit test other constructive methods.
slide-73
SLIDE 73

CSC309-S15-L4 Slide 73

Class testing, cont’d

  • 1. Start with unit tests for constructors.
  • 2. Next, unit test other constructive methods.
  • 3. Unit test selector methods.
slide-74
SLIDE 74

CSC309-S15-L4 Slide 74

Class testing, cont’d

  • 1. Start with unit tests for constructors.
  • 2. Next, unit test other constructive methods.
  • 3. Unit test selector methods.
  • 4. Test certain method interleavings.
slide-75
SLIDE 75

CSC309-S15-L4 Slide 75

Class testing, cont’d

  • 1. Start with unit tests for constructors.
  • 2. Next, unit test other constructive methods.
  • 3. Unit test selector methods.
  • 4. Test certain method interleavings.
  • 5. Stress test.
slide-76
SLIDE 76

CSC309-S15-L4 Slide 76

Class testing, cont’d

  • D. Use/write a test driver that:
slide-77
SLIDE 77

CSC309-S15-L4 Slide 77

Class testing, cont’d

  • D. Use/write a test driver that:
  • 1. executes each method test plan,
slide-78
SLIDE 78

CSC309-S15-L4 Slide 78

Class testing, cont’d

  • D. Use/write a test driver that:
  • 1. executes each method test plan,
  • 2. compares actual with expected output,
slide-79
SLIDE 79

CSC309-S15-L4 Slide 79

Class testing, cont’d

  • D. Use/write a test driver that:
  • 1. executes each method test plan,
  • 2. compares actual with expected output,
  • 3. reports the differences, if any,
slide-80
SLIDE 80

CSC309-S15-L4 Slide 80

Class testing, cont’d

  • D. Use/write a test driver that:
  • 1. executes each method test plan,
  • 2. compares actual with expected output,
  • 3. reports the differences, if any,
  • 4. optionally records output results.
slide-81
SLIDE 81

CSC309-S15-L4 Slide 81

Class testing, cont’d

  • E. Concrete examples:

projects/work/calendar/testing/ implementation/source/java/ caltool/schedule/ ScheduleTest.java projects/work/calendar/testing/ implementation/source/java/ caltool/caldb/ UserCalendarTest.java

slide-82
SLIDE 82

CSC309-S15-L4 Slide 82

Class testing, cont’d

  • F. Java details
slide-83
SLIDE 83

CSC309-S15-L4 Slide 83

Class testing, cont’d

  • F. Java details
  • 1. Each class X has companion testing class

named XTest.

slide-84
SLIDE 84

CSC309-S15-L4 Slide 84

Class testing, cont’d

  • F. Java details
  • 1. Each class X has companion testing class

named XTest.

  • 2. Test class may extend class it tests.
slide-85
SLIDE 85

CSC309-S15-L4 Slide 85

Class testing, cont’d

  • F. Java details
  • 1. Each class X has companion testing class

named XTest.

  • 2. Test class may extend class it tests.
  • 3. Each method X.f has a companion unit test

method named XTest.testF.

slide-86
SLIDE 86

CSC309-S15-L4 Slide 86

Class testing, cont’d

  • 3. Comment at top of test class describes the

module test plan.

slide-87
SLIDE 87

CSC309-S15-L4 Slide 87

Class testing, cont’d

  • 3. Comment at top of test class describes the

module test plan.

  • 4. The comment for each unit test method

describes unit test plan.

slide-88
SLIDE 88

CSC309-S15-L4 Slide 88

Class testing, cont’d

  • 3. Comment at top of test class describes the

module test plan.

  • 4. The comment for each unit test method

describes unit test plan.

  • 5. Each tested class implements dump

method for dumping test values as String.

slide-89
SLIDE 89

CSC309-S15-L4 Slide 89

  • XI. Integration testing
slide-90
SLIDE 90

CSC309-S15-L4 Slide 90

  • XI. Integration testing
  • A. Once tested, modules are integrated.
slide-91
SLIDE 91

CSC309-S15-L4 Slide 91

  • XI. Integration testing
  • A. Once tested, modules are integrated.
  • B. Stubs replaced with actual methods.
slide-92
SLIDE 92

CSC309-S15-L4 Slide 92

  • XI. Integration testing
  • A. Once tested, modules are integrated.
  • B. Stubs replaced with actual methods.
  • C. Test plan for top-most method(s) rerun with

integrated modules.

slide-93
SLIDE 93

CSC309-S15-L4 Slide 93

  • XI. Integration testing
  • A. Once tested, modules are integrated.
  • B. Stubs replaced with actual methods.
  • C. Test plan for top-most method(s) rerun with

integrated modules.

  • D. Continues until entire system is integrated.
slide-94
SLIDE 94

CSC309-S15-L4 Slide 94

  • D. Integration testing
  • A. Once tested, modules are integrated.
  • B. Stubs replaced with actual methods.
  • C. Test plan for top-most method(s) rerun with

integrated modules.

  • D. Continues until entire system is integrated.
slide-95
SLIDE 95

CSC309-S15-L4 Slide 95

Integration testing, cont’d

  • E. Concrete example:

projects/work/calendar/testing/ implementation/ integration-test-plan.html

slide-96
SLIDE 96

CSC309-S15-L4 Slide 96

  • 1. Integrate schedule + caldb
slide-97
SLIDE 97

CSC309-S15-L4 Slide 97

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
slide-98
SLIDE 98

CSC309-S15-L4 Slide 98

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
slide-99
SLIDE 99

CSC309-S15-L4 Slide 99

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
  • 4. Integrate caldb + caldb.server
slide-100
SLIDE 100

CSC309-S15-L4 Slide 100

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
  • 4. Integrate caldb + caldb.server
  • 5. Add caldb.server to schedule + ...
slide-101
SLIDE 101

CSC309-S15-L4 Slide 101

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
  • 4. Integrate caldb + caldb.server
  • 5. Add caldb.server to schedule + ...
  • 6. Add options to schedule + ...
slide-102
SLIDE 102

CSC309-S15-L4 Slide 102

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
  • 4. Integrate caldb + caldb.server
  • 5. Add caldb.server to schedule + ...
  • 6. Add options to schedule + ...
  • 7. Add file to schedule + ...
slide-103
SLIDE 103

CSC309-S15-L4 Slide 103

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
  • 4. Integrate caldb + caldb.server
  • 5. Add caldb.server to schedule + ...
  • 6. Add options to schedule + ...
  • 7. Add file to schedule + ...
  • 8. Add edit

schedule + ...

slide-104
SLIDE 104

CSC309-S15-L4 Slide 104

  • 1. Integrate schedule + caldb
  • 2. Add view to schedule+caldb
  • 3. Add admin to schedule+view+caldb
  • 4. Integrate caldb + caldb.server
  • 5. Add caldb.server to schedule + ...
  • 6. Add options to schedule + ...
  • 7. Add file to schedule + ...
  • 8. Add edit

schedule + ...

  • 9. Add top-level caltool classes
slide-105
SLIDE 105

CSC309-S15-L4 Slide 105

  • XII. Black box testing heuristics
slide-106
SLIDE 106

CSC309-S15-L4 Slide 106

  • XII. Black box testing heuristics
  • A. Provide inputs where the precondition is true,

varying inputs to exercise precond logic.

slide-107
SLIDE 107

CSC309-S15-L4 Slide 107

  • XII. Black box testing heuristics
  • A. Provide inputs where the precondition is true,

varying inputs to exercise precond logic.

  • B. Provide inputs where the precond is false,

if not a by-contract method.

slide-108
SLIDE 108

CSC309-S15-L4 Slide 108

Black box heuristics, cont’d

  • B. For data ranges:
slide-109
SLIDE 109

CSC309-S15-L4 Slide 109

Black box heuristics, cont’d

  • B. For data ranges:
  • 1. Provide inputs below, within, above each

precond range.

slide-110
SLIDE 110

CSC309-S15-L4 Slide 110

Black box heuristics, cont’d

  • B. For data ranges:
  • 1. Provide inputs below, within, above each

precond range.

  • 2. Provide inputs that produce outputs at bot-

tom, within, at top of each postcond range.

slide-111
SLIDE 111

CSC309-S15-L4 Slide 111

Black box heuristics, cont’d

slide-112
SLIDE 112

CSC309-S15-L4 Slide 112

Black box heuristics, cont’d

  • C. With and/or logic, provide test cases that

fully exercise logic.

slide-113
SLIDE 113

CSC309-S15-L4 Slide 113

Black box heuristics, cont’d

  • C. With and/or logic, provide test cases that

fully exercise logic.

  • 1. Provide an input that makes each clause

both true and false.

slide-114
SLIDE 114

CSC309-S15-L4 Slide 114

Black box heuristics, cont’d

  • C. With and/or logic, provide test cases that

fully exercise logic.

  • 1. Provide an input that makes each clause

both true and false.

  • 2. This means 2n test cases, where n is number
  • f logical terms.
slide-115
SLIDE 115

CSC309-S15-L4 Slide 115

Black box heuristics, cont’d

  • D. Provide selected combinations of inputs.
slide-116
SLIDE 116

CSC309-S15-L4 Slide 116

Black box heuristics, cont’d

  • D. Provide selected combinations of inputs.
  • 1. Combinatorially explosive in general.
slide-117
SLIDE 117

CSC309-S15-L4 Slide 117

Black box heuristics, cont’d

  • D. Provide selected combinations of inputs.
  • 1. Combinatorially explosive in general.
  • 2. Pairwise combination is practical approach.
slide-118
SLIDE 118

CSC309-S15-L4 Slide 118

Black box heuristics, cont’d

  • D. Provide selected combinations of inputs.
  • 1. Combinatorially explosive in general.
  • 2. Pairwise combination is practical approach.
  • 3. Used by Spest generator.
slide-119
SLIDE 119

CSC309-S15-L4 Slide 119

Black box heuristics, cont’d

  • D. Provide selected combinations of inputs.
  • 1. Combinatorially explosive in general.
  • 2. Pairwise combination is practical approach.
  • 3. Used by Spest generator.
  • 4. See pairwise.org
slide-120
SLIDE 120

CSC309-S15-L4 Slide 120

Black box heuristics, cont’d

  • E. For collection classes:
slide-121
SLIDE 121

CSC309-S15-L4 Slide 121

Black box heuristics, cont’d

  • E. For collection classes:
  • 1. Test empty collection.
slide-122
SLIDE 122

CSC309-S15-L4 Slide 122

Black box heuristics, cont’d

  • E. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
slide-123
SLIDE 123

CSC309-S15-L4 Slide 123

Black box heuristics, cont’d

  • E. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
slide-124
SLIDE 124

CSC309-S15-L4 Slide 124

Black box heuristics, cont’d

  • E. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
  • 4. Delete each element.
slide-125
SLIDE 125

CSC309-S15-L4 Slide 125

Black box heuristics, cont’d

  • E. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
  • 4. Delete each element.
  • 5. Repeat add/del sequence.
slide-126
SLIDE 126

CSC309-S15-L4 Slide 126

Black box heuristics, cont’d

  • E. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
  • 4. Delete each element.
  • 5. Repeat add/del sequence.
  • 6. Stress test with order of magnitude greater

than expected size.

slide-127
SLIDE 127

CSC309-S15-L4 Slide 127

  • XIII. Function paths
  • A. Control flow through method body.
  • B. Branching defines path separation point.
  • C. An old-school flow chart show paths clearly.
  • D. Each path is labeled with a number.
slide-128
SLIDE 128

CSC309-S15-L4 Slide 128

  • XIV. White box testing heuristics
  • A. Exercise each path at least once.
  • B. For loops:
  • 1. zero times (if appropriate),
  • 2. one time
  • 3. two times
  • 4. a substantial number of times
  • 5. max number times (if appro)
slide-129
SLIDE 129

CSC309-S15-L4 Slide 129

White box heuristics, cont’d

  • C. Provide inputs to reveal imple’n flaws:
  • 1. particular operation sequences
  • 2. inputs of particular size or range
  • 3. inputs that may cause overflow, underflow,
  • ther abnormal behavior
  • 4. inputs that test well-known problems in

algorithm

slide-130
SLIDE 130

CSC309-S15-L4 Slide 130

  • XV. Reconciling path coverage
  • A. Write purely black box tests.
  • B. To ensure coverage, execute under path cov-

erage analyzer.

  • C. If analyzer reports paths not being covered,

strengthen black box tests.

slide-131
SLIDE 131

CSC309-S15-L4 Slide 131

Reconciling path coverage

  • 1. Uncovered paths may contain useless or

dead code.

  • 2. When legitimate code, add new black box

test cases.

  • D. Complete "grey box" test plan can have path

column:

slide-132
SLIDE 132

CSC309-S15-L4 Slide 132

Reconciling path coverage

Test No. Inputs Expected Output Remarks Path i parm 1= ref parm 1 = p ... ... parm m = ref parm n =

slide-133
SLIDE 133

CSC309-S15-L4 Slide 133

  • XVI. Large inputs and outputs
  • A. For collections classes, i/o can grow large.
  • B. Can be specified as file data.
  • C. Referred to in test plans.
slide-134
SLIDE 134

CSC309-S15-L4 Slide 134

  • XVII. Test drivers
  • A. Once defined, test must be executed.
  • B. Test driver written as stand-alone program.
  • 1. Executes all tests.
  • 2. Records results.
  • 3. Provides result differencer.
slide-135
SLIDE 135

CSC309-S15-L4 Slide 135

Test drivers, con’td

  • C. Automated in

projects/work/calendar/testing/ implementation/source/java/Makefile

Template in

classes/309/lib/csl-Makefiles/ testing-Makefile

  • D. Perform tests initially using debugger.
slide-136
SLIDE 136

CSC309-S15-L4 Slide 136

  • XVIII. Testing concrete UIs
  • A. Performed in the same basic manner.
  • B. User input is simulated.
  • C. Output screens validated initially by human.
  • D. Machine-readable form of screen to compare

results mechanically.

slide-137
SLIDE 137

CSC309-S15-L4 Slide 137

Testing concrete UIs, cont’d

  • E. We’ll look at mechanized GUI testing

in a couple weeks.

slide-138
SLIDE 138

CSC309-S15-L4 Slide 138

  • XIX. Unit test is "dress rehearsal"

for integration testing ...

  • A. Integration "should not" reveal further errors.
  • B. From experience, it often does.
  • C. In so doing, individual tests become stronger.
slide-139
SLIDE 139

CSC309-S15-L4 Slide 139

  • XX. Testing with large data.
  • A. Suppose we have

class SomeModestModel { ... } class HumongousDatabase { ... }

slide-140
SLIDE 140

CSC309-S15-L4 Slide 140

Large-data requirements, cont’d

  • B. Modest amount of test data can be built pro-

grammatically, i.e., by calling constructive methods

  • C. Large amount of (persistent) data can be

stored external from program, built by exter- nal means if appropriate.

  • D. The latter are external test fixtures.
slide-141
SLIDE 141

CSC309-S15-L4 Slide 141

  • XXI. Other testing terminology
  • A. The testing oracle.
  • 1. Someone(thing) who knows correct

answers.

  • 2. Used to define expected results.
  • 3. Also used to analyze incorrect test results.
  • 4. In CSC 309, oracle is defined by implemen-

tation of Spest postcondition.

slide-142
SLIDE 142

CSC309-S15-L4 Slide 142

Terminology, cont’d

  • 5. When building truly experimental code,

spec-based oracle may not be possible.

  • a. E.g., AI systems.
  • b. Need initial prototype development.
slide-143
SLIDE 143

CSC309-S15-L4 Slide 143

Terminology, cont’d

  • B. Regression testing
  • 1. Run all tests whenever any change is made.
  • 2. Must happen before release.
  • 3. Ideally happens much more often.
  • 4. Ongoing research on "smart" regression.
slide-144
SLIDE 144

CSC309-S15-L4 Slide 144

Terminology, cont’d

  • C. Mutation testing
  • 1. It’s a way to test the tests.
  • 2. Strategy -- mutate program, then rerun

tests.

  • 3. E.g., "if (x < y)" is mutated to "if (x >= y)".
slide-145
SLIDE 145

CSC309-S15-L4 Slide 145

Terminology, cont’d

  • 4. With such mutation, tests should fail where

the mutated code produces bad result.

  • 5. If previously successful tests do not fail, ...

?

slide-146
SLIDE 146

CSC309-S15-L4 Slide 146

Terminology, cont’d

  • a. The tests are too weak and need to be

strengthened.

  • b. The mutated section of code was "dead"

and should be removed.

slide-147
SLIDE 147

CSC309-S15-L4 Slide 147

Terminology, cont’d

  • 6. Generally, the first of these is the case.
  • 7. Mutation can be used systematically to:
slide-148
SLIDE 148

CSC309-S15-L4 Slide 148

Terminology, cont’d

  • a. Provide measure of testing effectiveness.
  • b. Compare different testing strategies.
slide-149
SLIDE 149

CSC309-S15-L4 Slide 149

  • XXII. Testing directory structure
  • A. Figure 1 in notes ...
slide-150
SLIDE 150

CSC309-S15-L4 Slide 150 *.{h,C} project-specific package directories with .java files design implementation c++ diffs project-specific package directories iwth .class files JVM INTEL java ... T *.html javadoc images Makefile source executables Makefile input

  • utput-good
  • utput

*.o

  • utput

diffs

slide-151
SLIDE 151

CSC309-S15-L4 Slide 151

Test dir structure, cont’d

  • B. Contents of testing subdirs:
slide-152
SLIDE 152

CSC309-S15-L4 Slide 152

Directory or File Description *Test.java Implementation of class testing plans. input Test data input files used by test classes.

  • utput-good

Output results from last good run of the tests.

  • utput-prev-good

Previous good results, in case current results were erroneously confirmed to be good. $PLATFORM/output Current platform-specific output results. $PLATFORM/diffs Differences between current and good results. $PLATFORM/Makefile Makefile to compile tests, execute tests, and difference current results with good results. $PLATFORM/.make* Shell scripts called from the Makefile to per- form specific testing tasks. $PLATFORM/ .../*.class Test implementation object files.

slide-153
SLIDE 153

CSC309-S15-L4 Slide 153