Control-Flow Testing - Lecture Notes | SE 320, Study notes of Engineering

Material Type: Notes; Professor: Mancoridis; Class: Software Verification and Validation; Subject: Software Engineering; University: Drexel University; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-7lg-1
koofers-user-7lg-1 🇺🇸

10 documents

1 / 48

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Topics in Software Dynamic
White-box Testing
Part 1: Control-flow Testing
[Reading assignment: Chapter 7, pp. 105-122 plus many
things in slides that are not in the book …]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30

Partial preview of the text

Download Control-Flow Testing - Lecture Notes | SE 320 and more Study notes Engineering in PDF only on Docsity!

Topics in Software Dynamic

White-box Testing

Part 1: Control-flow Testing

[Reading assignment: Chapter 7, pp. 105-122 plus many things in slides that are not in the book …]

Control-Flow Testing

  • Control-flow testing is a structural testing strategy that uses the program’s control flow as a model.
  • Control-flow testing techniques are based on judiciously selecting a set of test paths through the program.
  • The set of paths chosen is used to achieve a certain measure of testing thoroughness. - E.g., pick enough paths to assure that every source statement is executed as least once.

Control Flowgraphs

  • The control flowgraph is a graphical representation of a program’s control structure.

Flowgraphs Consist of

Three Primitives

  • A decision is a program point at which the control can diverge. - ( e.g., if and case statements).
  • A junction is a program point where the control flow can merge. - ( e.g., end if, end loop, goto label)
  • A process block is a sequence of program statements uninterrupted by either decisions or junctions. ( i.e., straight-line code). - A process has one entry and one exit. - A program does not jump into or out of a process.

Bubble Sort Algorithm

1 2 3 4 5 6 7 1 for (j=1; j<N; j++) { last = N - j + 1; 2 for (k=1; k<last; k++) { 3 if (list[k] > list[k+1]) { temp = list[k]; list[k] = list[k+1]; list[k+1] = temp; 4 } 5 } 6 } 7 print(“Done\n”);

Paths

  • A path through a program is a sequence of

statements that starts at an entry, junction, or

decision and ends at another (possible the

same), junction, decision, or exit.

  • A path may go through several junctions,

processes, or decisions, one or more times.

  • Paths consist of segments.
  • The smallest segment is a link. A link is a

single process that lies between 2 nodes.

Paths (Cont’d)

  • Complete paths are useful for testing because: - It is difficult to set up and execute paths

that start at an arbitrary statement.

  • It is difficult to stop at an arbitrary

statement without changing the code being

tested.

  • We think of routines as input/output paths.

Path Selection Criteria

  • There are many paths between the entry and exit points of a typical routine.
  • Even a small routine can have a large number of paths.

Demonstration that

2 does not imply 3

  • 2.Statement Coverage: For x < 0 the program produces the correct result AND every statement has been executed.
  • 3.Branch Coverage: Would have found the bug! Therefore 2 does not imply 3. 1 2 Correct Code 1 if (x >= 0 ) { x = x + A; } 2 x = x + A Buggy Code 1 if (x >= 0 ) { /* missing statement */ } 2 x = x + A

Demonstration that

3 Does not Imply 2

  • Branch Coverage: Does not exercise dead code. Therefore 3 does not imply 2.
  • However, 3 implies 2 for programs written in a structured programming language without goto statements. 1 if (x < 0) { 2 goto 200; x = x + A } else x = x + A 3 200: x = x + A 1 2 3

Control-flow Testing

Criteria (Cont’d)

    1. Statement Testing ( ):
    • 100% statement coverage.
    • Execute all statements in a program at least once under some test.
    1. Branch Testing ( ):
    • 100% branch coverage.
    • Execute enough tests to assure that every branch alternative has been exercised at least once under some test.

1

P

2

P

P " P " ... " P

Common Sense Strategies

  • Statement and branch coverage have been used for over two decades as a minimum mandatory unit test requirement for new code developed at IBM and other companies.
  • Insisting on statement and branch coverage is based on common sense rather than theory.

Quote

“The more we learn about testing, the more we realize that

statement and branch coverage are minimum floors below

which we dare not fall, rather that ceilings to which we

should aspire.”

- B. Beizer.

Which Paths?

  • You must pick enough paths to achieve

statement and branch coverage.

  • Question: What is the fewest number of

paths to achieve statement and branch

coverage?

  • Answer: Unask the question.
    • It is better to take many simple paths than a few complicated ones.
    • There is no harm in taking paths that will exercise the same code more than once.