• No results found

Testing Methods_White Box Testing_3

N/A
N/A
Protected

Academic year: 2020

Share "Testing Methods_White Box Testing_3"

Copied!
36
0
0

Loading.... (view fulltext now)

Full text

(1)

TESTING

METHODS

LECTURE 3 : WEEK 3

SEN 460

: FALL 2016

(2)

Learning Outcome

Code coverage testing

Decision coverage

Condition coverage

Branch coverage

Loop coverage

Path coverage

Data coverage testing

Data flow coverage

(3)

Decision Coverage

Decision (Branch) Coverage Method

Causes every

decision

(if, switch, while, etc.) in

the program to be made both ways (or every

possible way for switch)

System

: Design a test case to exercise each

decision in the program each way (true / false)

Completion criterion

: A test case for each side of

each decision

(4)
(5)

Example Decision Coverage

Read A

Read B

IF A+B > 10 THEN

Print "A+B is Large"

ENDIF

(6)

Example Decision Coverage

Read A

Read B

IF A+B > 10 THEN

Print "A+B is Large"

ENDIF

(7)

Example Decision Coverage

To calculate Decision Coverage, one has to find

out the minimum number of paths which will

ensure that all the edges are covered. The aim

is to cover all possible true/false decisions.

(1) 1A-2C-3D-E-4G-5H

(2) 1A-2B-E-4F

(8)

Condition Coverage

Condition Coverage Method

 Like decision coverage, but causes every condition expression

to be exercised both ways (true / false)

 A condition is any true / false subexpression in a decision

Example:

if (( x == 1 || y > 2) && z < 3)

 Requires separate condition coverage tests for each of: x == 1 true / false

y > 2 true / falsez < 3 true / false

 More effective than simple decision coverage since exercises

(9)

Condition Coverage

if ((A || B) && C)

{

<< Few Statements >>

}

else

{

(10)

Condition Coverage

So, in our example, the 3 following

tests would be sufficient for 100%

Condition coverage testing.

A = true | B = not eval | C = false

A = false | B = true | C = true

(11)

Loop Coverage Method

 Most programs do their real work in do, while and for loops

 This method makes tests to exercise each loop in the program in four

different states

 execute body zero times (do not enter loop)  execute body once (i.e., do not repeat)

 execute body twice (i.e., repeat once)  execute body many times

 Usually used as an enhancement of a statement, block, decision or

condition coverage method

 System: Devise test cases to exercise each loop with zero, one, two

and many repetitions

 Completion criterion: A test for each of these cases for each loop

(12)
(13)

Loop Coverage Method

if there is an upper bound, 

n

, on the number of

times the loop body can be executed, then the

following cases should also be applied.

Design a test in which the loop body is executed

exactly 

n

-1 times.

Design a test in which the loop body is executed

exactly 

n

 times.

Try to design a test causing the loop body to be

(14)

Loop Coverage Method

Apply the following guidelines to ensure that each loop is tested at its boundaries (that is, with both minimal and maximal

numbers of iterations of the loop body) while using a number of tests that is only linear in the number of loops:

 Conduct the ``simple loop tests'' for the innermost loop (which

is a simple loop), while keeping the number of iterations of the outer loops at their minimal nonzero values.

 Work outward, conducting tests (as described above) for each

(15)

Execution Paths

An

execution

path

is a sequence of executed

statements starting at the

entry

to the unit (usually

the first statement) and ending at the

exit

from the

unit (usually the last statement)

Two paths are

independent

if there is at least one

statement on one path which is not executed on the

other

Path

analysis

(also know as

cyclomatic

complexity

analysis) identifies all the

independent

paths

(16)

Cyclomatic Complexity

Region, R= 6

Number of Nodes = 13

Number of edges = 17

(17)

Cyclomatic Complexity

 Cyclomatic Complexity for a flow graph is computed in one of three ways:

 The numbers of regions of the flow graph correspond to the Cyclomatic

complexity.

 Cyclomatic complexity, V(G), for a flow graph G is defined as

V(G) = E – N + 2

where E is the number of flow graph edges and N is the number of flow graph nodes.

 Cyclomatic complexity, V(G), for a graph flow G is also defined as

V(G) = P + 1

(18)

Cyclomatic Complexity

Cyclomatic Complexity, V( C) :

V( C ) = R = 6;

Or

V(C) = Predicate Nodes + 1

=5+1 =6

Or

(19)

Execution Paths Analysis

Flow Graphs

It is easiest to do path analysis if we look at the execution

flow

graph

of the program or unit

The flow graph simply shows program

control

flow

between

(20)
(21)

Execution Paths Analysis

To achieve 100% basis path coverage,

you need to define your basis set. The

cyclomatic complexity of this method is

four (one plus the number of decisions),

so you need to define four linearly

independent paths. To do this, you pick

an arbitrary first path as a baseline, and

then flip decisions one at a time until

(22)

Execution Paths Analysis

Path 1: Any path will do for your baseline, so pick true for the decisions' outcomes

(represented as TTT). This is the first path in your basis set.

Path 2: To find the next basis path, flip the first decision (only) in your baseline, giving you FTT for your desired decision outcomes.

Path 3: You flip the second decision in your baseline path, giving you TFT for your third basis path. In this case, the first baseline decision remains fixed with the true outcome.

Path 4: Finally, you flip the third decision in your baseline path, giving you TTF for your fourth basis path. In this case, the first baseline decision remains fixed with the true outcome.

(23)

Path Coverage Testing

Advantages

Covers all basic blocks (does all of basic block

testing)

Covers all conditions (does all of decision/condition

testing)

Does all of both, but with fewer tests!

Automatable (in practice requires automation)

Disadvantages

(24)

Path Coverage Testing Disadvantages

Example:

These

fragments

should

be tested the same

way, since they

actually implement

the same solution -

but the one on the

left gets

five

tests,

whereas the one on

the right gets only

(25)

White Box Data Coverage

Data Coverage Methods

Data coverage methods explicitly try to

cover the

data

aspects of the program

code, rather than the

control

aspects

In this course we will cover data

flow

(26)

White Box Data Coverage

Data Flow Coverage

 Data flow coverage is concerned with variable definitions and

uses along execution paths

 A variable is defined if it is assigned a new value during a

statement execution

A variable definition in one statement is alive in another if

there is a path between the two statements that does not redefine the

variable

 There are two types of variable uses

A P-use of a variable is a predicate use (e.g. if statement)

A C-use of a variable is a computation use or any other use (e.g. I/O

(27)
(28)
(29)
(30)
(31)
(32)

White Box Data Coverage

Data Flow Coverage

There are a variety of different

testing

strategies

related to

data flow:

 All-Uses coverage: test all uses of each definition  All-Defs coverage: test each definition at least once

 All C-Uses/Some P-Uses coverage: test all computation uses. If

no computation uses for a given definition then test at least one predicate use

 All P-Uses/Some C-Uses coverage: test all predicate uses. If no

predicate uses for a given definition then test at least one computation use

(33)

White Box Data Coverage

Data Flow Coverage

We have covered definitions of data, uses of data,

and testing strategies for data flow coverage.

System

: Identify definitions (and uses) of variables

and testing strategy. design a set of test cases that

cover the testing strategy

Completion criterion

: Depends on the test strategy.

(34)

Summary

Testing Methods: White Box Testing II

Code coverage methods:

Decision analysis methods

(decision, condition, loop coverage, path

coverage)

Data coverage methods:

(35)
(36)

Any Questions !!!

END OF LECTURE

References

Related documents

Anwar and Sampath (2000) examine the export led growth hypothesis for 97 countries (including India, Pakistan and Sri Lanka) for the period 1960–1992 using cointegration and

All of the participants were faculty members, currently working in a higher education setting, teaching adapted physical activity / education courses and, finally, were

This paper describes our experiences using Active Learning in four first-year computer science and industrial engineering courses at the School of Engineering of the Universidad

Speaking a Java idiom, methods are synchronized, that is each method of the same object is executed in mutual exclusion, and method invocations are asynchronous, that is the

The purpose of this study was to evaluate the diagnostic utility of real-time elastography (RTE) in differentiat- ing between reactive and metastatic cervical lymph nodes (LN)

Now you will be ready to put on the button knots. These can cover a length of anywhere from 16 to 22 inches. For this measurement I start from the very outside tip of the eye.

Considering the estimates of mode of inheritance and heterosis effect compared to better parent analysis showed that for efficient progress in SYP and TSW

- Detoxification and Substance Abuse Treatment - Seeking Drug Abuse Treatment Know What to Ask - ANGER University of Massachusetts Medical School - Client Satisfaction Evaluations