1 note content copyright © 2004 ian sommerville. nu-specific content copyright © 2004 m. e. kabay....

49
Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software Engineering Lecture #31 – 2004-11-12 M. E. Kabay, PhD, CISSP Assoc. Prof. Information Assurance Division of Business & Management, Norwich University mailto:[email protected] V: 802.479.7937

Upload: daniel-jacobs

Post on 26-Mar-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Software Testing

IS301 – Software EngineeringLecture #31 – 2004-11-12

M. E. Kabay, PhD, CISSP

Assoc. Prof. Information AssuranceDivision of Business & Management, Norwich University mailto:[email protected] V: 802.479.7937

Page 2: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

2 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Topics

Defect Testing Integration TestingObject-Oriented TestingTesting Workbenches

Page 3: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

3 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Defect Testing

Testing programs to establish presence of system defects

Page 4: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

4 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Process

Component testing Testing of individual program componentsUsually responsibility of component

developer (except sometimes for critical systems)

Tests derived from developer’s experience Integration testing

Testing of groups of components integrated to create system or sub-system

responsibility of independent testing teamTests based on system specification

Page 5: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

5 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Phases

Componenttesting

Integrationtesting

Software developer Independent testing team

Page 6: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

6 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Defect Testing

Goal of defect testing to discover defects in programs

Successful defect test test which causes program to behave in anomalous way

Tests show presence not absence of defects

Page 7: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

7 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing priorities

Only exhaustive testing can show program free from defects. However, exhaustive testing impossible

Tests should exercise system's capabilities rather than its components

Testing old capabilities more important than testing new capabilities

Testing typical situations more important than boundary value cases

Page 8: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

8 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Test Data and Test Cases

Test data Inputs which have been devised to test

systemTest cases

Inputs to test system plusPredicted outputs from these inputs

If system operates according to its specification

Page 9: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

9 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Defect Testing Process

Design testcases

Prepare testdata

Run programwith test data

Compare resultsto test cases

Testcases

Testdata

Testresults

Testreports

Page 10: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

10 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Black-Box Testing

Program considered as ‘black-box’Test cases based on system specification Test planning can begin early in software

process

Page 11: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

11 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Black-Box Testing

Ie

Input test data

OeOutput test results

System

Inputs causinganomalousbehaviour

Outputs which revealthe presence ofdefects

Page 12: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

12 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Equivalence Partitioning

Input data and output results often fall into different classes where all members of class related

Each of these classes = equivalence partition where program behaves in equivalent way for each class member

Test cases should be chosen from each partition

Page 13: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

13 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Equivalence Partitioning (1)

System

Outputs

Invalid inputs Valid inputs

Page 14: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

14 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Equivalence partitioning (2)

Partition system inputs and outputs into ‘equivalence sets’; e.g.,If input 5-digit integer

between 10,000 and 99,999, then equivalence partitions are

<10,000, 10,000-99,999 and >99,999

Choose test cases at boundaries of these sets:00000, 09999, 10000, 10001, 99998, 99999,

& 100000

Page 15: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

15 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Equivalence Partitioning (3)

Between 10000 and 99999Less than 10000 More than 99999

999910000 50000

10000099999

Input values

Between 4 and 10Less than 4 More than 10

34 7

1110

Number of input values

Page 16: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

16 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Search Routine Specification

procedure Search (Key : ELEM ; T: ELEM_ARRAY; Found : in out BOOLEAN; L: in out ELEM_INDEX) ;

Pre-condition-- array has at least one elementT’FIRST <= T’LAST

Post-condition-- element found and referenced by L( Found and T (L) = Key)

or -- element not in array( not Found and

not (exists i, T’FIRST >= i <= T’LAST, T (i) = Key ))

Page 17: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

17 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Search Routine - Input Partitions

Inputs which conform to pre-conditions Inputs where pre-condition does not hold Inputs where key element is member of

array Inputs where key element not member

of array

Page 18: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

18 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Guidelines (Sequences)

Test software with sequences which have only single value

Use sequences of different sizes in different tests

Derive tests so that first, middle and last elements of sequence accessed

Test with sequences of zero length

Page 19: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

19 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Search Routine - Input Partitions

Page 20: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

20 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Structural Testing

Sometime called white-box testingDerivation of test cases according to program

structure. Knowledge of program used to identify

additional test casesObjective to exercise

all program statements not all path combinations

Page 21: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

21 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

White-Box Testing

Componentcode

Testoutputs

Test data

DerivesTests

Page 22: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

23 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Binary Search – Equiv. Partitions

Pre-conditions satisfied, key element in arrayPre-conditions satisfied, key element not in

arrayPre-conditions unsatisfied, key element in

arrayPre-conditions unsatisfied, key element not in

array Input array has single value Input array has even number of values Input array has odd number of values

Page 23: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

24 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Binary Search – Equiv. Partitions

Mid-point

Elements < Mid Elements > Mid

Equivalence class boundaries

Page 24: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

25 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Binary Search – Test Cases

Page 25: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

26 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Path Testing

Objective: ensure each path through program executed at least once

Starting point: flow graphShows nodes representing program

decisionsArcs representing flow of control

Statements with conditions therefore = nodes in flow graph

Page 26: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

27 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Program Flow Graphs

Each branch shown as separate pathLoops shown by arrows looping back to loop

condition nodeBasis for computing cyclomatic

complexityCyclomatic complexity = Number of edges -

Number of nodes + 2

Page 27: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

28 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Cyclomatic Complexity

Number of tests needed to test all control statements equals cyclomatic complexity

Cyclomatic complexity equals number of conditions in program

Useful if used with care. Does not imply adequacy of testing.

Although all paths executed, all combinations of paths not necessarily executed

Page 28: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

Binary Search Flow Graph1

2

3

4

65

7

while bottom <= top

if (elemArray [mid] == key

(if (elemArray [mid]< key8

9

bottom > top

Page 29: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

30 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Independent Paths

1, 2, 3, 8, 9 1, 2, 3, 4, 6, 7, 2 1, 2, 3, 4, 5, 7, 2 1, 2, 3, 4, 6, 7, 2, 8, 9 Test cases should be

derived so that all of these paths executed

Dynamic program analyzer may be used to check that paths have been executed

1

2

3

4

65

7

while bottom <= top

if (elemArray [mid] == key

(if (elemArray [mid]< key8

9

bottom > top

Page 30: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

31 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Integration Testing

Tests complete systems or subsystems composed of integrated components

Integration testing should be black-box testing with tests derived from specification

Main difficulty is localizing errors Incremental integration testing reduces this

problem

Page 31: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

32 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Incremental Integration Testing

T3

T2

T1

T4

T5

A

B

C

D

T2

T1

T3

T4

A

B

C

T1

T2

T3

A

B

Test sequence1

Test sequence2

Test sequence3

Page 32: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

33 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Approaches to Integration Testing

Top-down testingStart with high-level system and integrate

from top-down replacing individual components by stubs where appropriate

Bottom-up testingIntegrate individual components in levels

until complete system created In practice, most integration involves

combination of these strategies

Page 33: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

34 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Top-Down Testing

Level 2Level 2Level 2Level 2

Level 1 Level 1Testing

sequence

Level 2stubs

Level 3stubs

. . .

Page 34: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

35 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Bottom-Up Testing

Level NLevel NLevel NLevel NLevel N

Level N–1 Level N–1Level N–1

Testingsequence

Testdrivers

Testdrivers

Page 35: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

36 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Approaches

Architectural validationTop-down integration testing better at

discovering errors in system architectureSystem demonstration

Top-down integration testing allows limited demonstration at early stage in development

Test implementationOften easier with bottom-up integration testing

Test observation – what’s happening during test?Problems with both approachesExtra code may be required to observe tests

Instrumenting the code

Page 36: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

37 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Interface Testing

Takes place when modules or sub-systems integrated to create larger systems

Objective: Detect faults due toInterface errors or Invalid assumptions about interfaces

Particularly important for object-oriented development Objects defined by their interfaces

Page 37: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

38 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Interface Testing

Testcases

BA

C

Page 38: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

39 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Interface Types

Parameter interfacesData passed from one procedure to another

Shared-memory interfacesBlock of memory shared between / among

proceduresProcedural interfaces

Sub-system encapsulates set of procedures to be called by other sub-systems

Message-passing interfacesSub-systems request services from other

sub-systems

Page 39: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

40 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Interface Errors

Interface misuseCalling component makes error use of

interface; e.g. parameters in wrong order Interface misunderstanding

Calling component embeds incorrect assumptions about behavior of called component

Timing errorsCalled and calling component operate at

different speedsOut-of-date information accessed“Race conditions”

Page 40: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

41 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Interface Testing Guidelines

Parameters to called procedure at extreme ends of their ranges

Always test pointer parameters with null pointers

Design tests which cause component to failUse stress testing in message passing

systems (see next slide) In shared-memory systems, vary order in

which components activatedWhy?

Page 41: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

42 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Stress Testing

Exercises system beyond its maximum design loadStressing system often causes defects to

come to light Stressing system tests failure behavior

Should not fail catastrophicallyCheck for unacceptable loss of service or

dataDistributed systems

Non-linear performance degradation

Page 42: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

48 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Approaches to Cluster Testing

Use-case or scenario testingTesting based on user interactions with

systemTests system features as experienced by

usersThread testing

Tests systems response to events as processing threads through system

Object interaction testingTests sequences of object interactions Stop when object operation does not call

on services from another object

Page 43: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

49 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Scenario-Based Testing

Identify scenarios from use-cases Supplement with interaction diagrams Show objects involved in scenario

Consider scenario in weather station system where report generated (next slide)

Page 44: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

52 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Workbenches

Testing expensiveWorkbenches

Range of toolsReduce

Time required and Total testing costs

Most testing workbenches are open systemsTesting needs are organization-specificDifficult to integrate with closed design

and analysis workbenches

Page 45: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

53 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Workbench

Page 46: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

54 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Testing Workbench Adaptation

Scripts User interface simulators andPatterns for test data generators

Test outputsMay have to be prepared manually for

comparisonSpecial-purpose file comparators may be

developed

Page 47: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

55 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Required Homework

Read-recite-review Chapter 23 of Sommerville’s text

Survey-Question Chapter 24 for MondayQuiz on WEDNESDAY 17th Nov:

Chapters 17-21Required

For Fri 19 Nov 2004 for 35 points23.1 & 23.3 (@5)23.4 & 23.5 (@10)23.7 (@5)

Page 48: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

56 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

Optional Homework

By Mon 29 Nov 2004, for up to 14 extra points, complete any or all of23.2, 23.6, 23.8 (@2)23.9 (@5)23.10 (@3)

Page 49: 1 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved. Software Testing IS301 – Software

57 Note content copyright © 2004 Ian Sommerville. NU-specific content copyright © 2004 M. E. Kabay. All rights reserved.

DISCUSSION