Top Banner
1 UNIT TESTING - Complexity Reference: + Software Testing Course @ Lonsdale System +Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric @ Arthur: H. Watson + Thomas J. McCabe
16
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lec.unit testing   control flow

1

UNIT TESTING - Complexity

Reference:

+ Software Testing Course @ Lonsdale System

+Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric

@ Arthur: H. Watson + Thomas J. McCabe

Page 2: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

2

Control flow graphs

Cyclomatic complexity can be used for 2 purposes:

As a defect prevention technique

To determine the number of structural test cases that will execute all of independent paths through a program

Page 3: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

3

Control flow graph

Page 4: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

4

Control flow graph

Page 5: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

5

Cyclomatic complexity

Complexity = number of edges –number of nodes + 2

Sequence = 1-2+2 =1

If … then ... Else = (2-2+2) = 2

Repeat … until = (3-3+2) = 2

While do … end = (3-3+2) = 2

Case = (7-5+2) = 4

Page 6: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

6

Page 7: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

7

Page 8: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

8

Complexity = 13 -10 + 2=5

Page 9: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

9

Comlexity for AND & OR

Complexity = (9-7+2) = 4

Page 10: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

10

Page 11: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

11

Page 12: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

12

Exercise

Page 13: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

13

Exercise

Page 14: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

14

Page 15: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

15

Page 16: Lec.unit testing   control flow

HCMUNS – FIT – SE Dept - ST Course

16

Alternative Approaches to Counting Complexity

Too simple

Complexity = number of decision predicates + 1

Let check examples again !