23
Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

Embed Size (px)

Citation preview

Page 1: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

Overview of Software Testing

07/12/2013

WISTPC 2013

Peter Clarke

Page 2: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

Outline of Presentation

• Testing Terminology

• Testing Approaches

• Levels of Testing

• Unit Testing

2

Page 3: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

CEN 4010 Class 17 - 7/11 4

Overview of Testing - Terminology

• Software testing is the dynamic verification of the behavior of a program on a finite set of test cases, suitably selected from the usually infinite execution domain, against the expected behavior.

(Guide to the Software Engineering Body of Knowledge 2004 Version)

Page 5: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

5

Page 6: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

6

Introduction to Testing Theory

D RF

d..F(d)

T

tF(t)

Page 7: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

7

Page 8: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

8

Page 9: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

9

Page 10: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

10

Page 11: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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)

11

Page 12: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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

12

Page 13: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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).

13

Page 14: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

14

Page 15: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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

15

Example: Valid inputs to test the getNumberDaysInMonth() method

Page 16: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

Unit Testing – Boundary Analysis

• Test cases are generated using the extremes of the input domain, e.g. maximum, minimum, just inside/outside boundaries, typical values, and error values.

• It is similar to Equivalence Partitioning but focuses on "corner cases“.

Exercise: write test case input using boundary analysis for the getNumberDaysInMonth() method.

16

Page 17: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter 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.

17

Page 18: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

18

Control Flow Adequacy Criteria cont

Example: Source codepublic int Fun(int x){ k = 0; 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

Page 19: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

19

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.

Exercise: Indentify value(s) of x to execute every stmt in Fun(int x) at least once.

Page 20: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

20

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.

Exercise: Indentify value(s) of x to execute every branch in Fun(int x) at least once.

Page 21: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

21

HomeworkSource code

1. public int Fun1(int x, int y){2. k = 0;3. while (x <= 10 && k < 10){4. if (x%2 != 0){5. k = k + y;6. k = k – 2;7. }8. x = x + 1;9. k = x + k;10. }11. if (x < 0){12. x = y;13. k = k + x;14. }15. return k;16. }

1. Draw a flow graph2. Identify pairs of values for

for x and y that gives:(a) 100% statement coverage(b) 100% branch coverage

Page 22: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

22

Summary

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

• Testing Approaches – blackbox, whitebox, and graybox testing

• Levels of Testing – unit, integration, system

Page 23: Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke

23

Summary cont

• Unit Testing

– Blackbox: equivalence partitioning and boundary analysis.

– Whitebox: statement coverage, branch coverage.

• Practice exercises were given for each testing technique.