introduction to software testing 06/23/2010 wistpc 2010 peter j. clarke

44
Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Upload: kerry-bell

Post on 13-Dec-2015

227 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Introduction to Software Testing

06/23/2010

WISTPC 2010

Peter J. Clarke

Page 2: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Outline of Presentation

• Testing terminology

• Introduction to Testing Theory

• Testing Concepts

• Laws of Testing

• Levels of Testing

• Unit Testing

2

Page 3: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

What is software testing?

• Software testing is the process of operating software under specified conditions, observing or recording the results and making an evaluation of some aspect of the software.

(IEEE/ANSI std 610.12-1990)

3

Page 4: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Terminology

The following defns are taken from Binder 2000 and McGregor & Sykes 2001.

• Failure – is the manifested inability of a system or component to perform a required function within specified limits e.g. abnormal termination, or unmet time and space constraints of the software.

• Fault - incorrect step, process, or data definition in the software.

• Error - a human action that produces a fault.

4

Page 5: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Terminology cont

• A bug refers to an error or a fault.

• Debugging is the process of tracking down the source of failures (errors and/or faults) and making repairs.

• A test case specifies the pretest state of the component under test (CUT) and its environment, the test inputs and conditions, and the expected results.

• A test point is a specific value for test case input state variables.

5

Page 6: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Terminology cont

• A test suite is a collection of test cases, typically related to some testing goal or criterion.

• A test driver is a class or utility program that applies test cases to a CUT.

• A stub is a partial, temporary implementation of a component.

• A test harness is a system of test drivers and other tools to support test execution.

6

Page 7: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

7

Introduction to Testing Theory

Basic defns:

F is a program, D is the domain and R the output for F. i.e., F: D R

On input d D, F (if it terminates) produces output F(d) R.

F is correct on input d (abbreviated OK(d) ) if F(d) exists and OUT(d, F(d)), i.e., OUT(d, F(d)) is true iff F(d) is an acceptable result.

OUT can be considered the specification for F.

Page 8: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

8

Introduction to Testing Theory

D RF

d..F(d)

T

tF(t)

T constitutes and ideal test if OK(t) for all t T implies OK(d) for all d D.

Page 9: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

9

Introduction to Testing Theory cont

Basic defns cont:

A test T for program F is simply a finite subset of D.

If T = D then we have exhaustive testing and the above holds. It is usually impractical to perform exhaustive testing

A test is successful iff ( t T) OK(t))

Page 10: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Concepts

Test Case components:

1. Name – identifies the test case, it is a good idea to derive the name from the requirement being tested.

2. Purpose – states the purpose of the test and relates it to the requirement (or scenario).

3. Test set up – describe the h/w and s/w and environment required for a successful test.

4. Input – description of the input data or commands.

5. Expected output (or Oracle) – expected test results against which the output of the test is compared.

6. Actual output (or log) – output produced by the test.

10

Page 11: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Concepts cont• Test cases are classified depending on which

aspect of the system model is tested:

– Blackbox (specification-based or functional) tests focus on the input/output behavior (or functionality) of the component. Tests do not deal with the internal aspects of the component nor with the behavior or the structure of the components.

– Whitebox (structural or implementation-based) tests focus on the internal structure of the component. That is, test cases are constructed based on the code that implements the software.

11

Page 12: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Concepts cont

• Combination of blackbox and whitebox testing is referred to as graybox testing.

• Regression testing includes the re-execution of prior tests after a change, this ensures that the functionality that worked before the change has not been affected.

12

Page 13: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Testing Concepts cont

• Test criteria - The criteria that a system or component must meet in order to pass a given test. [IEEE 610]

There are two types of testing criteria:

1. Test data selection criterion – represents a rule used to determine which test cases to select.

2. Test data adequacy criterion – a rule used determine whether or not sufficient testing has been performed.

13

Page 14: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Laws of Testing Handbook of SSE

• Testing can show the presence but not the absence of errors (Dijkstra).

• A developer is unsuited to test his or her code (Weinberg’s).

• Approximately 80 percent of defects come from 20 percent of modules (Paret-Zipf-type)

• Suspicion-based testing can be more effective than most other approaches (Hamlet’s hypothesis).

14

Page 15: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Levels of Testing• Unit Testing - refers to tests that verify the

functionality of a specific section of code, usually at the function level. In an object-oriented environment, this is usually at the class level, and the minimal unit tests include the constructors and destructors. (wikipedia, 2010)

• Integration Testing - is any type of software testing that seeks to verify the interfaces between components against a software design. Components may be integrated in an iterative way or all together ("big bang"). (wikipedia, 2010)

15

Page 16: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Levels of Testing• System Testing - testing a completely integrated

system to verify that it meets its requirements. (wikipedia, 2010)

See http://en.wikipedia.org/wiki/Software_testing

• Let us take a look at the Premium Bank Account (FBA) specification and Java program

16

Page 17: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing

• Focuses on the building blocks of the software

system i.e., objects and subsystems.

• Many unit testing techniques have been devised

including: equivalence testing, state-based testing, boundary testing, domain testing, control flow-based testing (statement, branch, MCC, basis path, path).

17

Page 18: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Equivalence Partitioning

• Equivalence partitioning is a blackbox testing technique that minimizes the number of test cases.

• Possible inputs are partitioned into equivalence testing classes, and a test case is selected from each class.

• Assumption - system behaves in a similar way for all members of an equiv. class.

• Criteria used to determine equivalence classes: coverage, disjointedness, representation.

18

Page 19: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Equivalence Partitioning

Equivalence class Value for month input Value for year input

Months with 31 days, non-leap yrs.

7 (July) 1901

Months with 31 days, leap yrs. 7 (July) 1904

Months with 30 days, non-leap yrs.

6 (June) 1901

Months with 30 days, leap yrs. 6 (June) 1904

Months with 28 or 29 days, non-leap yrs.

2 (February) 1901

Months with 28 or 29 days, leap yrs.

2 (February) 1904

19

Example: Valid inputs to test the getNumberDaysInMonth() method

Page 20: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Equivalence Partitioning

Exercise:

1. Identify at least two (2) test cases for the FBA program using equivalence testing for part (1) of the specification.

2. Perform a walkthrough (trace) of the program to determine if the program is correct with respect to the specification.

3. Repeat steps 1 and 2 for the other parts of the specification i.e., parts 2, 3, 4, 5.

20

Page 21: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – State-based

• State-based testing exercises the implementation to see whether it produces the correct response for different transitions in some model of the system. Blackbox testing technique.

• A state machine is an abstraction composed of events (inputs), states, and actions (outputs).

• A state machine has four building blocks– State – an abstraction that summarizes the information

form the past that helps determine the behavior for the future.

– Transition – an allowable tow state sequence. A transition is cause by an event.

event-name arg-list ‘[‘ guard-condition’]’ ‘/’ action-expr21

Page 22: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – State-based– Event – An input or an interval of time

– Action - The result or output that follows an event.

22

Full

Loaded

Empty pop/EmptyStackException

pop [n == 1] / return top(x)

pop [n > 1] / return top(x)

push(x)

push(x) [n < max-1]

pop / return top(x)push(x) [n == max-1]

push(x) / FullStackException

Example of state machine model of Stack with guards

Page 23: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

23

Specification-based Testing cont

Test generation for state-based models:

• Piecewise coverage - all states, all events, all actions.

• All Transitions

• All n-Transition Sequences

• All Round-trip Paths

• M-length Signature

Page 24: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

24

Exhaustive

Strategy

M-lengthSignature

All Round-trip Paths

All Transition k-tuples

All Transitions

All States All Events All Actions

Faults Revealed

All possible invalid statesAll event and action faults

All invalid statesUp to M extra statesAll event and action faults

All invalid/missing statesSome extra statesAll event and action faults

All event and action faultsSome missing/invalid states

Some event and action faults

Fig. State-based test power hierarchy

Page 25: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – State-based

Exercise:

1. Create a state machine from the FBA specification.

2. Identify test cases that covers the all states, all events and all transitions criteria.

3. Identify test cases that covers the all 2-transitions sequences criteria.

25

Page 26: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Boundary Analysis

• Is used in conjunction with equivalence partitioning in that it focuses on a source of faults - the boundaries of an equivalence partition. Blackbox testing technique.

• Test data derived by examining the edges of an equivalence partition.

• One form of domain testing is based on boundary analysis:

1. Indentify constraints for all input variables (boundaries)

2. Select test values for each variable in each boundary (on point)

26

Page 27: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Boundary Analysis

3. Select test values that do not lie on any boundary (off point)

4. Select test values that satisfies all boundaries but do not lie on the boundary (in point).

5. Select test values that do not satisfy any boundary condition (out point).

Stack Example:

empty (Stack.size() == 0)

loaded (Stack.size() > 0) && Stack.size() < MAXSTACK)

full (Stack.size() == MAXSTACK)

27

Page 28: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Boundary Analysis

28

State Possible Transitions

In Point On Point Off Point

Empty Loaded 0 0 1

Loaded Empty 1<x<32766 1 0

Full 1<x<32766 32766 32767

Full Loaded 32767 32767 32766

Assume MAXSTACK = 32767

P184 in Testing Object-Oriented Systems by Binder.

Page 29: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Boundary Analysis

Exercise:

1. Identify test cases for the FBA program using boundary analysis (in, on, off) for part (1) of the specification.

2. Perform a walkthrough (trace) of the program to determine if the program is correct with respect to the specification.

3. Repeat steps 1 and 2 for the other parts of the specification i.e., parts 2, 3, 4, 5.

29

Page 30: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Domain Analysis

• Domain testing is a blackbox testing technique that can be used to identify efficient and effective test cases when multiple variables can or should be tested together.

• It builds on and generalizes equivalence class and boundary value testing to n simultaneous dimensions. Like those techniques the tester is searching for situations where the boundary has been defined or implemented incorrectly.

• Think about the solutions for an n-dimensional space.

30

Page 31: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Control Flow Adequacy CriteriaFlow Graph (FG) [Binder 00]

- A segment is represented by a node in the FG (a sphere). A segment is one or more contiguous statements with no conditionally executed statements.

- A conditional transfer of control is a branch. A branch is represented by an outgoing edge in the FG.

- The entry point of a method is represented by the entry node, which is a node no incoming edges. The exit point of a method is represented by the exit node, which has no outbound edges.

31

Page 32: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Control Flow Adequacy Criteria cont

Example: Source codepublic int Fun(

int x, int K){ while (x <= 10 && k < 3){

if (x%2 != 0)k = k + 1;

x = x + 1; } if (x < 0){

x = 10;k = 0;

} return k;}

K=0

x<=10 && k<3

x%2 != 0

x=x+1

k=k+1

return k

B

C

D

E

F

I

EntryFlow graph

A

X<0

X = 10K = 0

T

F

TT

FF

G

H

32

Page 33: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

33

Unit Testing – Statement Coverage

1. Statement coverage – A set P of execution paths satisfies the statement coverage criterion iff for all nodes n in the FG, there is at least one path p in P s.t. n is on the path p. Whitebox testing technique.

• Generate test data to execute every stmt in the program at least once.

• Give a value(s) of x and k in the example that satisfies statement coverage.

Page 34: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

34

Unit Testing – Branch Coverage

2. Branch coverage – A set P of execution paths satisfies the branch coverage criterion iff for all edges e in the FG, there is at least one path p in P s.t. p contains edge e. Whitebox testing technique.

• Generate test data to exercise the true and false outcomes of every decision.

• Give a value(s) of x and k in the example that satisfies branch coverage.

Page 35: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

35

Unit Testing – MCC Coverage

3. Multiple Condition Coverage (MCC) – A test set T is said to be adequate according to the multiple-condition-coverage criterion if, for every condition C, which consists of atomic predicates (p1, p2, …,pn), and all the possible combinations (b1, b2, …,bn) of their truth values,

there is al least one test case in T s.t. the value of pi equals bi, i= 1, 2, …,n.

Whitebox testing technique.

Page 36: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

36

Unit Testing – MCC Coverage cont

• Generate test data to exercise all possible combinations of true and false outcomes of conditions within a decision.

• Give a value(s) of x and k in the example that satisfies MCC coverage.

Page 37: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Path Coverage

4. Path coverage – A set P of execution paths satisfies the path coverage criterion iff P contains all execution paths from the begin node to the end node in the FG. Whitebox testing technique.

• Generate test data to exercise all paths in the program. Note every path through a loop is considered to be different and distinct.

• Give a value(s) of x and k in the example that satisfies path coverage.

37

Page 38: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Basis Path Coverage

5. Cyclomatic-Number Criterion – A set P of execution paths satisfies the cyclomatic number criterion iff P contains at least one set of v independent paths, where v = e – n + p is the cyclomatic number of the FG.

• n - number of vertices, e - is the number of edges, p - is the number of strongly connected components.

• A graph is strongly connected if, for any two nodes a and b there exists a path from a to b and a path from b to a.

38

Page 39: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Basis Path Coverage

• Basis path testing – is a way of easily identifying the upper bound for the number of paths necessary in order to achieve branch coverage. Whitebox testing technique.

v = (e + 1) - n + 1 McCabe Cycolmatic Complexity Number

• Note this is for a strongly connected FG, add edge from exit node to entry node, hence e + 1.

• Note some formulae include the extra edge in the “e”.

• Identify the basis set for the FG example.39

Page 40: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Control Flow Adequacy Criteria cont

Edge ABCGHI ABCGI ABCDEFCGHI ABCDFCGHI

A,B 1 1 1 1

B,C 1 1 1 1

C,D 0 0 1 1

D,E 0 0 1 0

E,F 0 0 1 0

D,F 0 0 0 1

F,C 0 1 1 1

C,G 1 1 1 1

G,H 1 0 1 1

G,I 1 1 0 0

H,I 1 0 1 1

40

Page 41: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Control Flow Adequacy Criteria cont

Points to note:

• Path coverage not always practical due to loops i.e., infinite number of paths.

• Statement and branch coverage are not finitely applicable due to dead code and infeasible branches.

• Can define a finitely applicable version of the criteria.

41

Page 42: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

Unit Testing – Whitebox testing

Exercise for each whitebox testing technique:

Using all the blackbox test cases developed for the PBA problems perform the following.

a) Build the FG for each method and perform a walkthrough to check if the coverage criteria is satisfied.

b) If the criteria is not satisfied add test cases to ensure the coverage criteria is satisfied.

42

Page 43: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

43

Summary

• Testing terminology – software testing, test case, test driver, stub, fault, failure, error

• Introduction to Testing Theory – relationship to functions and the concept of an ideal test.

• Testing Concepts – blackbox, whitebox, graybox testing

• Laws of Testing

• Levels of Testing – unit, integration, system

Page 44: Introduction to Software Testing 06/23/2010 WISTPC 2010 Peter J. Clarke

44

Summary cont

• Unit Testing

– Blackbox: equivalence partitioning, state-based, boundary analysis, domain analysis.

– Whitebox: statement coverage, branch coverage, multiple-condition coverage, path coverage, basis path coverage.

• Practice exercises were given for each testing technique.