Software Testing Fundamentals - WordPress.com

52
Software Testing Fundamentals There are two general approaches for software testing Black Box Testing - proper functioning of the s/w is tested - whether the s/w accepts the i/p properly & generates proper o/p. - external interfaces, external data & information – is tested. White Box Testing - procedural details are closely examined - internals of s/w are tested. - i.e. internal structures, logic paths, control flows, - data flows, internal data structures, conditional loops etc.

Transcript of Software Testing Fundamentals - WordPress.com

Page 1: Software Testing Fundamentals - WordPress.com

Software Testing Fundamentals • There are two general approaches for software testing

• Black Box Testing - proper functioning of the s/w is tested - whether the s/w accepts the i/p properly & generates

proper o/p. - external interfaces, external data & information – is tested. • White Box Testing - procedural details are closely examined - internals of s/w are tested. - i.e. internal structures, logic paths, control flows, - data flows, internal data structures, conditional loops etc.

Page 2: Software Testing Fundamentals - WordPress.com

Testability

• Operability—it operates cleanly

• Observability—the results of each test case are readily observed

• Controllability—the degree to which testing can be automated and optimized

• Decomposability—testing can be targeted

• Simplicity—reduce complex architecture and logic to simplify tests

• Stability—few changes are requested during testing

• Understandability—of the design

2

Page 3: Software Testing Fundamentals - WordPress.com

What is a “Good” Test?

• A good test has a high probability of finding an error

• A good test is not redundant.

• A good test should be “best of breed”

• A good test should be neither too simple nor too complex

3

Page 4: Software Testing Fundamentals - WordPress.com

Internal and External Views

• Any engineered product (and most other things) can be tested in one of two ways:

– Knowing the specified function

– that a product has been designed to perform,

– tests can be conducted that demonstrate each function is fully operational while at the same time searching for errors in each function;

– Knowing the internal workings of a product, tests can be conducted to ensure that "all gears mesh," that is, internal operations are performed according to specifications and all internal components have been adequately exercised.

4

Page 5: Software Testing Fundamentals - WordPress.com

Test Case Design

5

"Bugs lurk in corners and congregate at

boundaries ..."

Boris Beizer

OBJECTIVE

CRITERIA

CONSTRAINT

to uncover errors

in a complete manner

with a minimum of effort and time

Page 6: Software Testing Fundamentals - WordPress.com

Exhaustive Testing

6

loop < 20 X

There are 10 possible paths! If we execute one

test per millisecond, it would take 3,170 years to

test this program!!

14

Page 7: Software Testing Fundamentals - WordPress.com

Selective Testing

7

loop < 20 X

Selected path

Page 8: Software Testing Fundamentals - WordPress.com

Software Testing

8

Methods

Strategies

white-box

methods

black-box

methods

Page 9: Software Testing Fundamentals - WordPress.com

White Box Testing

Page 10: Software Testing Fundamentals - WordPress.com

White-Box Testing

... our goal is to ensure that all statements and conditions have been executed at least once ...

Page 11: Software Testing Fundamentals - WordPress.com

• Basis path testing

These slides are designed to

accompany Software Engineering: A

Practitioner’s Approach, 7/e (McGraw-

Hill 2009). Slides copyright 2009 by

Roger Pressman.

11

Page 12: Software Testing Fundamentals - WordPress.com

Basis Path Testing

• Every execution path will be tested at least once

• Steps –

1. Design flow graph for the program or a component

2. Calculate cyclomatic complexity

3. Select a basis set of path

4. Generate test cases for this paths

12

Page 13: Software Testing Fundamentals - WordPress.com

1. Design flow graph

for the program or a component

• Graphical representation of control flow of the program

• Contains –

- Nodes – represents one or more procedural statements

- Edges – represent control flow

- Regions – areas bounded by nodes and edges

Page 14: Software Testing Fundamentals - WordPress.com

2. Calculate Cyclomatic Complexity

• There are three ways to calculate CC

1. CC = Total number of regions in the flow graph

2. CC = E – N + 2

= number of edges – number of nodes + 2

3. CC = number of predicate nodes + 1

14

Page 15: Software Testing Fundamentals - WordPress.com

Basis Path Testing

15

First, we compute the cyclomatic complexity:

number of simple decisions + 1

or

number of enclosed areas + 1

In this case, V(G) = 4

Page 16: Software Testing Fundamentals - WordPress.com

3. Select Basis set of Path

Next, we derive the independent paths:

Since V(G) = 4, there are four paths

Path 1: 1,2,3,6,7,8

Path 2: 1,2,3,5,7,8

Path 3: 1,2,4,7,8

Path 4: 1,2,4,7,2,4,...7,8

Finally, we derive test cases to exercise these paths.

1

2

3

4

5 6

7

8

Page 17: Software Testing Fundamentals - WordPress.com

4. Generate Test Cases For This Paths Test case id

Test case name

Test case description

Test steps Test case status (pass/fail)

Test priority

Defect severity

step Expected Actual

1

2

3

4

5

Page 18: Software Testing Fundamentals - WordPress.com

Deriving Test Cases

• Summarizing: – Using the design or code as a foundation, draw a

corresponding flow graph.

– Determine the cyclomatic complexity of the resultant flow graph.

– Determine a basis set of linearly independent paths.

– Prepare test cases that will force execution of each path in the basis set.

Page 19: Software Testing Fundamentals - WordPress.com

What is Test case?

• A test case is a document, which has - - a set of test data, preconditions, - expected results and post conditions,

• developed for a particular test scenario - in order to verify compliance against a specific

requirement.

• Test Case acts as the starting point for the test execution, - and after applying a set of input values, - the application has a definitive outcome and - leaves the system at some end point or also known as

execution post condition.

Page 20: Software Testing Fundamentals - WordPress.com
Page 21: Software Testing Fundamentals - WordPress.com
Page 22: Software Testing Fundamentals - WordPress.com

Format of Standard Test Cases

(Below is format of a standard login Test case )

Test Case ID

Test Scenario

Test Steps Test Data Expected Results

Actual Results

Pass/Fail

TU01

Check Customer Login with valid Data

1.Go to site http://demo.guru99.com 2.Enter UserId 3.Enter Password 4.Click Submit

Userid = guru99 Password = pass99

User should Login into application

As Expected

Pass

TU02

Check Customer Login with invalid Data

1.Go to site http://demo.guru99.com 2.Enter UserId 3.Enter Password 4.Click Submit

Userid = guru99 Password = glass99

User should not Login into application

As Expected

Pass

Page 23: Software Testing Fundamentals - WordPress.com

• Below are the standard fields of sample test case template:

• Test case ID: - Unique ID for each test case. - Follow some convention to indicate types of test. - E.g. ‘TC_UI_1’ indicating ‘user interface test case #1’.

• Test priority (Low/Medium/High): - This is useful while test execution. - Test priority for business rules and functional test cases can be medium or

higher - whereas minor user interface cases can be low priority. - Test priority should be set by reviewer.

• Module Name – Mention name of main module or sub module.

• Test Designed By: Name of tester

• Test Designed Date: Date when wrote

• Test Executed By: - Name of tester who executed this test. To be filled after test execution.

Page 24: Software Testing Fundamentals - WordPress.com

• Test Execution Date: Date when test executed.

• Test Title/Name: - Test case title. - E.g. verify login page with valid username and password.

• Test Summary/Description: Describe test objective in brief.

• Pre-condition: - Any prerequisite that must be fulfilled - before execution of this test case. - List all pre-conditions in order to successfully execute this test case.

• Dependencies: - Mention any dependencies on other test cases or test requirement.

Page 25: Software Testing Fundamentals - WordPress.com

Graph Matrices

• A graph matrix is - a square matrix whose size - (i.e., number of rows and columns) - is equal to the number of nodes on a flow graph

• Each row and column corresponds to - an identified node, - and matrix entries correspond to connections (an

edge) between nodes.

• By adding a link weight to each matrix entry, - the graph matrix can become a powerful tool - for evaluating program control structure during

testing 25

Page 26: Software Testing Fundamentals - WordPress.com

Control Structure Testing

• Condition testing — a test case design method that exercises the logical conditions contained in a program module

• Data flow testing — selects test paths of a program according to the locations of definitions and uses of variables in the program

Page 27: Software Testing Fundamentals - WordPress.com

Loop Testing

Nested Loops

Concatenated

Loops Unstructured

Loops

Simple loop

Page 28: Software Testing Fundamentals - WordPress.com

Loop Testing: Simple Loops

Minimum conditions—Simple Loops

1. skip the loop entirely

2. only one pass through the loop

3. two passes through the loop

4. m passes through the loop m < n

5. (n-1), n, and (n+1) passes through the loop

where n is the maximum number

of allowable passes

Page 29: Software Testing Fundamentals - WordPress.com

Loop Testing: Nested Loops

Start at the innermost loop. Set all outer loops to their minimum iteration parameter values.

Test the min+1, typical, max-1 and max for the innermost loop, while holding the outer loops at their minimum values.

Move out one loop and set it up as in step 2, holding all other loops at typical values. Continue this step until the outermost loop has been tested.

If the loops are independent of one another

then treat each as a simple loop

else* treat as nested loops

endif*

for example, the final loop counter value of loop 1 is used to initialize loop 2.

Nested Loops

Concatenated Loops

Page 30: Software Testing Fundamentals - WordPress.com

Black Box Testing

Page 31: Software Testing Fundamentals - WordPress.com

• Also called – behavioral testing

• Functional requirements of the software are tested.

• Uncovers following type of errors – - incorrect or missing functions - interface errors - errors in data structure - performance errors - initialization or termination errors

Page 32: Software Testing Fundamentals - WordPress.com

Black-Box Testing

requirements

events input

output

Page 33: Software Testing Fundamentals - WordPress.com

Black-Box Testing

• How is functional validity tested?

• How is system behavior and performance tested?

• What classes of input will make good test cases?

• Is the system particularly sensitive to certain input values?

• How are the boundaries of a data class isolated?

• What data rates and data volume can the system tolerate?

• What effect will specific combinations of data have on system

operation?

Page 34: Software Testing Fundamentals - WordPress.com

Black Box Testing - Techniques

1. Equivalence Partitioning

2. Boundary Value Analysis

3. Graph Based Testing

Page 35: Software Testing Fundamentals - WordPress.com

1. Equivalence Partitioning

• Divides - input domain into classes of data

• From this data - test cases can be derived

• Equivalence classes - are evaluated for given input condition

• Equivalence class represents - a set of valid or invalid states - for input conditions

35

Page 36: Software Testing Fundamentals - WordPress.com

• If an input condition specifies a range,

• one valid and two invalid

• equivalence classes are defined

– Input range: 1 – 10

– Eq classes: {1..10}, {x < 1}, {x > 10}

• If an input condition requires a specific value,

• one valid and two invalid

• equivalence classes are defined

– Input value: 250

– Eq classes: {250}, {x < 250}, {x > 250}

Page 37: Software Testing Fundamentals - WordPress.com

• If an input condition specifies a member of a set,

• one valid and one invalid

• equivalence class are defined – Input set: {-2.5, 7.3, 8.4}

– Eq classes: {-2.5, 7.3, 8.4}, {any other x}

• If an input condition is a Boolean value,

• one valid and one invalid class are defined – Input: {true condition}

– Eq classes: {true condition}, {false condition}

Page 38: Software Testing Fundamentals - WordPress.com

2. Boundary Value Analysis

• A greater number of errors occur at the boundaries of the input domain rather than in the "center“

• Boundary value analysis is

- a test case design method

- that complements equivalence partitioning

– It selects test cases at the edges of a class

– It derives test cases from both the input domain and output domain

Page 39: Software Testing Fundamentals - WordPress.com

1. If an input condition specifies a range

- bounded by values a and b, - test cases should be designed with values a and b - as well as - values just above and just below a and b - ex. Integer D with input condition – [-2,10] test values - -2,10,11,-1,0

2. If an input condition specifies a number of values, - test case should be developed - that exercise - the minimum and maximum numbers.

- Values just above and just below - the minimum and maximum are also tested - ex. Integer E with input condition : {2,7,100,102} test values – 1,2,3,101,102,103

Page 40: Software Testing Fundamentals - WordPress.com

• Apply guidelines 1 and 2 to output conditions;

- produce output that reflects the minimum and the maximum values expected;

- also test the values just below and just above

• If internal program data structures have prescribed boundaries (e.g., an array),

- design a test case - to exercise the data structure - at its minimum and maximum boundaries

Page 41: Software Testing Fundamentals - WordPress.com

Boundary Value Analysis

- Guidelines 1 and 2 are applied to output condition.

- If internal program data structures have prescribed boundaries, be

certain to design a test case to exercise the data structure at its boundary

Such as data structures:

- array input condition:

empty,

single element, full element,

out-of-boundary

search for element:

- element is inside array or

- the element is not inside array

You can think about other data structures:

- list, set, stack, queue, and tree

Page 42: Software Testing Fundamentals - WordPress.com

3. Graph Based Testing

• Objects and their relationships are tested,

• By Creating – • Graph of - objects and their relationships,

• Node weight represents – - properties of an object • Link weight – represents – - properties of relationships of the objects

Page 43: Software Testing Fundamentals - WordPress.com

Graph-Based Methods

new

file

menu select generates

(generation time 1.0 sec)

document

window

document

text

is represented as

contains

Attributes:

background color: white

text color: default color or preferences

(b)

object#1

Directed link

(link weight)

object#2

object

#3

Undirected link

Parallel links

Node weight(value

)

(a)

allows editingof

To understand

• the objects

that are modeled in

software and

• the relationships

that connect these

objects

In this context, we

consider the term

“objects” in the broadest

possible context. It

encompasses data

objects, traditional

components (modules),

and object-oriented

elements of computer

software.

Page 44: Software Testing Fundamentals - WordPress.com

new

file

menu select generates

(generation time 1.0 sec)

document

window

document

text

is represented as

contains

Attributes:

background color: white

text color: default color or preferences

(b)

object#1

Directed link

(link weight)

object#2

object

#3

Undirected link

Parallel links

Node weight(value

)

(a)

allows editingof

Page 45: Software Testing Fundamentals - WordPress.com

Orthogonal Array Testing

• Used when the number of input parameters is small and the values that each of the parameters may take are clearly bounded

One input item at a time L9 orthogonal array

XY

Z

XY

Z

Page 46: Software Testing Fundamentals - WordPress.com

Equivalence Partitioning

These slides are designed to

accompany Software Engineering: A

Practitioner’s Approach, 7/e (McGraw-

Hill 2009). Slides copyright 2009 by

Roger Pressman.

46

user queries

mouse picks

output formats

prompts

FK input

data

Page 47: Software Testing Fundamentals - WordPress.com

Sample Equivalence Classes

user supplied commands

responses to system prompts

file names

computational data

physical parameters

bounding values

initiation values

output data formatting responses to error messages

graphical data (e.g., mouse picks)

data outside bounds of the program physically impossible data

proper value supplied in wrong place

Valid data

Invalid data

Page 48: Software Testing Fundamentals - WordPress.com

Boundary Value Analysis

user queries

mouse picks

output formats

prompts

FK input

data

output domain input domain

Page 49: Software Testing Fundamentals - WordPress.com

Comparison Testing • Used only in situations in which the reliability

of software is absolutely critical (e.g., human-rated systems) – Separate software engineering teams develop

independent versions of an application using the same specification

– Each version can be tested with the same test data to ensure that all provide identical output

– Then all versions are executed in parallel with real-time comparison of results to ensure consistency

These slides are designed to

accompany Software Engineering: A

Practitioner’s Approach, 7/e (McGraw-

Hill 2009). Slides copyright 2009 by

Roger Pressman.

49

Page 50: Software Testing Fundamentals - WordPress.com

Orthogonal Array Testing

• Used when the number of input parameters is small and the values that each of the parameters may take are clearly bounded

These slides are designed to

accompany Software Engineering: A

Practitioner’s Approach, 7/e (McGraw-

Hill 2009). Slides copyright 2009 by

Roger Pressman.

50

One input item at a time L9 orthogonal array

XY

Z

XY

Z

Page 51: Software Testing Fundamentals - WordPress.com

Model-Based Testing

• Analyze an existing behavioral model for the software or create one.

– Recall that a behavioral model indicates how software will respond to external events or stimuli.

• Traverse the behavioral model and specify the inputs that will force the software to make the transition from state to state.

– The inputs will trigger events that will cause the transition to occur.

• Review the behavioral model and note the expected outputs as the software makes the transition from state to state.

• Execute the test cases.

• Compare actual and expected results and take corrective action as required.

These slides are designed to

accompany Software Engineering: A

Practitioner’s Approach, 7/e (McGraw-

Hill 2009). Slides copyright 2009 by

Roger Pressman.

51

Page 52: Software Testing Fundamentals - WordPress.com

Software Testing Patterns

• Testing patterns are described in much the

same way as design patterns (Chapter 12).

• Example: • Pattern name: ScenarioTesting

• Abstract: Once unit and integration tests have been

conducted, there is a need to determine whether the

software will perform in a manner that satisfies users.

The ScenarioTesting pattern describes a technique for

exercising the software from the user’s point of view. A

failure at this level indicates that the software has failed

to meet a user visible requirement. [Kan01]