Docsity

Cyclomatic Complexity-Basics of Software Engineering-Lecture Slides, Slides of Software Engineering

Toggle sidebar
bg1
Cyclomatic Complexity
The number of tests to test all control statements equals
the cyclomatic complexity
Cyclomatic complexity equals number of conditions in a
program plus one (or equivalently, in the program flow
graph it is the “Number of edges - Number of nodes +2”)
Conditions are any type of branching operation such as
each “if” statement or any types of loop (for, while etc.)
Useful if used with care. Does not imply adequacy of
testing. Although all paths are executed, all combinations
of paths are not executed
1 COMP201 - Software Engineering
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Cyclomatic Complexity-Basics of Software Engineering-Lecture Slides and more Slides Software Engineering in PDF only on Docsity!

Cyclomatic Complexity

 The number of tests to test all control statements equals the cyclomatic complexity

 Cyclomatic complexity equals number of conditions in a program plus one (or equivalently, in the program flow graph it is the “Number of edges - Number of nodes +2”)

Conditions are any type of branching operation such as each “if” statement or any types of loop (for, while etc.)

 Useful if used with care. Does not imply adequacy of testing. Although all paths are executed, all combinations of paths are not executed

Binary search (Java)

class BinSearch { // This is an encapsulation of a binary search// ordered objects and a key and returns an object with 2 attributes namely function that takes an array of // index - the value of the array index// found - a boolean indicating whether or not the key is in the array //// reference to a function and so return An object is returned because two values it is not possible in Java to pass basic types by // the key is -1 if the element is not found public static void search ( int key, int [] elemArray, Result r ){ int bottom = 0 ;int top = elemArray.length - 1 ; int mid ;r.found = false ; r.index = -1 ; while ( bottom <= top ){ mid = (top + bottom) / 2 ;if (elemArray [mid] == key) { r.index = mid ; r.found = true ;return ; } // if partelse { if (elemArray [mid] < key) elsebottom = mid + 1 ; } top = mid - 1 ; } // search} //while loop } //BinSearch

Independent Paths

 Test cases should be derived so that all of these paths are executed

 A dynamic program analyser may be used to check that paths have been executed

Integration Testing

 Integration testing - tests complete systems or subsystems composed of integrated components

 Integration testing should be black-box testing with tests derived from the specification

 Main difficulty is localising errors

Incremental integration testing reduces this problem

Incremental Integration Testing

COMP201 - Software Engineering 7

  • Note that incremental integration as on the previous slide uses the idea of regression testing, i.e., future tests also test previous test cases again.
  • As a new module is added, we not only run a new test, we also make sure the addition of the new module does not “break” the previous test cases.
  • This can sometimes by done automatically by using a test harness (a program written to automatically generate test data and record their results). [See Junit for Java if you are interested in this.]

docsity.com

Approaches to Integration Testing

 Top-down testing

 Start with high-level system and integrate from the top- down replacing individual components by stubs where appropriate

 Bottom-up testing

 Integrate individual components in levels until the complete system is created

 In practice, most integration involves a combination of these strategies

Bottom-up Testing

Level N Level N Le vel N Level N Level N

Level N– 1 Level N– 1 Level N– 1

Testing sequence

Test drivers

Test drivers

For which types of system is bottom-up

testing appropriate, and why?

Object-oriented systems – because these have a neat decomposition into classes and methods – makes testing easy

real-time systems – because we can identify slow bits of code more quickly

systems with strict performance requirements – because we can measure the performance of individual methods early in the testing process

Interface Testing

 Takes place when modules or sub-systems are integrated to create larger systems

 Objectives are to detect faults due to interface errors or invalid assumptions about interfaces

 Particularly important for object-oriented development as objects are defined by their interfaces

Interface Testing

Test cases

A B

C

Interface Errors

 Interface misuse

 A calling component calls another component and makes an error in its use of its interface e.g. parameters in the wrong order

 Interface misunderstanding

 A calling component embeds assumptions about the behaviour of the called component which are incorrect

 Timing errors

 The called and the calling component operate at different speeds and out-of-date information is accessed

Interface Testing Guidelines

 Design tests so that parameters to a called procedure are at the extreme ends of their ranges

 Always test pointer parameters with null pointers

 Design tests which cause the component to fail

 Use stress testing in message passing systems

 In shared memory systems, vary the order in which components are activated

Object-Oriented Testing

 The components to be tested are object classes that are instantiated as objects

 Larger grain than individual functions so approaches to white-box testing have to be extended

 No obvious ‘top’ to the system for top-down integration and testing

Testing Levels

 Testing operations associated with objects

 Testing object classes

 Testing clusters of cooperating objects

 Testing the complete OO system