25
Nov 2002 91.3913 R McFadyen 1 A Traditional Software Development Process Unit test Integration test System test Detailed design Architectura l design Analysis Requireme nts analysis Business modeling process Business results

Nov 200291.3913 R McFadyen1 A Traditional Software Development Process Unit test Integration test System test Detailed design Architectural design Analysis

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Nov 2002 91.3913 R McFadyen 1

A Traditional Software Development Process

Unit test

Integration test

System test

Detailed design

Architectural design

Analysis

Requirements analysis

Business modeling process

Business results

Nov 2002 91.3913 R McFadyen 2

Black Team

Peopleware: Productive Projects and Teams

by Tom Demarco and Timothy Lister

Ch 19: The Black Team

•"legendary" Black Team at IBM in 60’s

•a particularly effective testing team

•the best testers at the company

•testers delighted in finding new ways to break software

•programmers dreaded having their software go through Black Team testing

•promoted themselves by dressing all in black

•the spirit of the Black Team has survived

Nov 2002 91.3913 R McFadyen 3

Testing

Unit testing •White-box testing•Black-box testing

Nov 2002 91.3913 R McFadyen 4

White-box Testing

•Tests are derived from knowledge of the software’s construction

•aka structural, glass-box, or clear-box testing

•Tester analyzes the code, the algorithm, to derive tests

Nov 2002 91.3913 R McFadyen 5

Whitebox testing

Tests are derived from knowledge of the software’s construction

Path testing: A whitebox testing technique based on flow of control

•Construct a flow graph for Cyclomatic Complexity

•gives us the maximum number of tests necessary to cover all edges in the flow graph

•Design test cases such that each transition is traversed at least once - examine each condition and select an input for the true branch and another for the false branch

•Each test should contain an edge that is not contained in any other test

Nov 2002 91.3913 R McFadyen 6

White-box Testing Example

FindMean(float Mean, FILE ScoreFile) …see next slide

What is the flow graph for FindMean?

What is the CC?

What tests can we generate from the flowgraph/CC … to know all paths have been executed?

Nov 2002 91.3913 R McFadyen 7

/*Read in and sum the scores*/

White-box Testing Example

FindMean(float Mean, FILE ScoreFile)

{ SumOfScores = 0.0; NumberOfScores = 0; Mean = 0;

Read(ScoreFile, Score);

while (! EOF(ScoreFile) {

if ( Score > 0.0 ) {

SumOfScores = SumOfScores + Score;

NumberOfScores++;

} Read(ScoreFile, Score);

}

/* Compute the mean and print the result */

if (NumberOfScores > 0 ) {

Mean = SumOfScores/NumberOfScores;

printf("The mean score is %f \n", Mean);

} else

printf("No scores found in file\n");

}

Nov 2002 91.3913 R McFadyen 8

Prepare for Flow Graph

FindMean (FILE ScoreFile){ float SumOfScores = 0.0;

int NumberOfScores = 0; float Mean=0.0; float Score;Read(ScoreFile, Score);while (! EOF(ScoreFile) {

if (Score > 0.0 ) {SumOfScores = SumOfScores + Score;NumberOfScores++;}

Read(ScoreFile, Score);}/* Compute the mean and print the result */if (NumberOfScores > 0) {

Mean = SumOfScores / NumberOfScores;printf(“ The mean score is %f\n”, Mean);

} elseprintf (“No scores found in file\n”);

}

1

2

3

4

5

7

6

89

Nov 2002 91.3913 R McFadyen 9

Constructing the Logic Flow Diagram

4

3

2

1

5

6

7 8

9

CC = 11-9+2 = 4

1, 2, 6, 8, 9

1, 2, 6, 7, 9 is not possible

1, 2, 3, 4, 5, 2, 6, 7, 9

1, 2, 3, 4, 5, 2, 6, 8, 9 is not possible

1, 2, 3, 5, 2, 6, 8, 9

1, 2, 3, 5, 2, 6, 7, 9 is not possible

ok

ok

ok

Note: If node 4 is included then node 7 must be included

These 3 tests cover all paths! We didn’t need 4!

Every line of code is tested!

Nov 2002 91.3913 R McFadyen 10

Constructing the Logic Flow Diagram

4

3

2

1

5

6

7 8

9

CC = 11-9+2 = 4

1, 2, 6, 8, 9

Test with no records in the file

Nov 2002 91.3913 R McFadyen 11

Constructing the Logic Flow Diagram

4

3

2

1

5

6

7 8

9

CC = 11-9+2 = 4

1, 2, 3, 4, 5, 2, 6, 7, 9

A test with one positive score

Nov 2002 91.3913 R McFadyen 12

Constructing the Logic Flow Diagram

4

3

2

1

5

6

7 8

9

CC = 11-9+2 = 4

1, 2, 3, 5, 2, 6, 8, 9

A test with one negative score

Nov 2002 91.3913 R McFadyen 13

Black-box Testing

• A blackbox test is one that focuses on the input/output behaviour of a component without considering its implementation

• The system being tested is a black box, whose behaviour is determined by studying its inputs and outputs

• aka functional testing since it is concerned with functionality and not implementation

• Can use equivalence classes and boundary conditions

Nov 2002 91.3913 R McFadyen 14

Equivalence class testing

• A technique to minimize the number of test cases• An equivalence class is a set of tests with common characteristics• A test case is selected for each class• We use our domain knowledge to generate equivalence classes• Example: suppose a method returns the number of days in a

month, given the month and year.– When we consider months, we could arrive at 3 equivalence

classes:• months with 31 days• months with 30 days• months with 28 or 29 days

– When we consider years, we have two equivalence classes: leap years and non-leap years

– Combining, we have 6 equivalence classes

Nov 2002 91.3913 R McFadyen 15

Six equivalence classes

Equivalence classInput values

month year

31 day month, non-leap year 7 1901

31 day month, leap year 7 1904

30 day month, non-leap year 6 1901

30 day month, leap year 6 1904

28/29 day month, non-leap year 2 1901

28/29 day month, leap year 2 1904

Nov 2002 91.3913 R McFadyen 16

Boundary class testing

•We focus on the boundary conditions of equivalence classes

•Rather than selecting any element in an equivalence class, boundary testing requires that elements be selected from the “edges”

Example

•In general, years that are multiples of 4 are leap years; years that are multiples of 100 are not leap years, unless they are multiples of 400.

•2000 is a leap year, but 1900 is not

•For Year, 2000 and 1900 are good boundary cases

•0 and 13 would be good boundary cases for month

Nov 2002 91.3913 R McFadyen 17

Ten testing classes

Equivalence classInput values

month year31 day month, non-leap year 7 1901

31 day month, leap year 7 1904

30 day month, non-leap year 6 1901

30 day month, leap year 6 1904

28/29 day month, non-leap year 2 1901

28/29 day month, leap year 2 1904

Leap year divisible by 400 2 2000

Non-leap year divisible by 100 2 1900

Non-positive invalid month 0 1904

positive invalid month 13 1904

Nov 2002 91.3913 R McFadyen 18

Example

How would knowledge of the algorithm (the code) affect your choices of equivalence classes and boundary classes?

• First, suppose you are testing a search method. What equivalence and boundary test classes would you use? What are your black-box test classes?

• Next, suppose you learn the search is a binary search … how might this knowledge affect your set of test classes …

Nov 2002 91.3913 R McFadyen 19

Example (continued):

Suppose we have a search module to test. We know:

– the list, elt, must have at least one element

– if the element, key, is found, found will be true and elt[L] = key

– if the key is not found, found will be false

How do we structure, or organize, our test cases?

Nov 2002 91.3913 R McFadyen 20

• How do we structure, or organize, our test cases?

• We have two types of searches: successful and unsuccessful. So, we can partition our search test cases into two classifications: found and not found

• When it comes to lists of elements, we know that lists of length 1, are special cases or boundary points. So, we should have 2 partitions of lists: length 1, and length of more than one.

• When an element is searched for, it can be found in boundary positions. So, we can should have 3 partitions: found at the start, found at the end, and then we should include where it is found in the middle.

Example (continued):

Nov 2002 91.3913 R McFadyen 21

Found Not Found

List of 1 element List of 1 element

•combining the partitions

List of >1 element

In 1st position

In last position

In middle position

List of >1 element

1 2

3

4

5

6

Example (continued):

Nov 2002 91.3913 R McFadyen 22

55

44

•sample tests for the 6 partitions

55 33 88 44

22 33 6 77 88 44

33 66 77 88 22

22 55 88 66 77

1

2

6

4

5

3

55 true, 1

55 false, ?

55 true, 1

44 true, 6

77 true, 3

99 false, ?

Outputs Found, L

Inputs List Key

Example (continued):

Nov 2002 91.3913 R McFadyen 23

•Now, suppose we are examining the algorithm that searches an ordered list for a specific value in Key.

•On examination we see it’s a binary search and we see that it really treats the List as having 3 sections:

elements < midmid-point

elements > mid

Example (continued):

Nov 2002 91.3913 R McFadyen 24

•:We can use this knowledge to further refine our partitioning - we need to test for where the Key we are looking for is at the boundary points for these partitions.

elements < midmid-point

elements > mid

We’ll add two more tests relating to the boundary points – finding a key just before, and just after the midpoint.

(Could there be more that we should add related to not finding a key? What is the control flowgraph?)

Example (continued):

Nov 2002 91.3913 R McFadyen 25

Example (continued)

55

44

55 66 77 88 99

22 33 44 50 56 61 76

22 33 44 50 56 61 76

22 33 44 50 56 61 76

1

2

6

4

5

7

55 true, 1

55 false, ?

55 true, 1

50 true, 4

76 true, 7

44 true, 3

Outputs Found, L

Inputs List Key

22 33 44 50 56 61 768 56 true, 522 55 88 66 773 99 false, ?