CSC 480 Software Engineering Lecture 15 Oct 21, 2002.
-
Upload
chad-allen -
Category
Documents
-
view
212 -
download
0
Transcript of CSC 480 Software Engineering Lecture 15 Oct 21, 2002.
![Page 1: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/1.jpg)
CSC 480 Software Engineering
Lecture 15Oct 21, 2002
![Page 2: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/2.jpg)
White-box Testing
Based on knowledge of structural details Objective and coverage
Every statement has been executed at least once Every linearly independent path has been traversed at
least once Path coverage ensures statement coverage
![Page 3: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/3.jpg)
Flow Chart vs. Flow Graph
![Page 4: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/4.jpg)
Binary search (Java)
class BinSearch { 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 part else { if (elemArray [mid] < key) bottom = mid + 1 ; else top = mid - 1 ; } } //while loop } // search } //BinSearch
This is an encapsulation of a binary search function that takes an array of ordered objects and a key and returns an object with 2 attributes namely
index - the value of the array index found - a boolean indicating whether or not the key is in the array
An object is returned because it is not possible in Java to pass basic types by reference to a function and so return two valuesthe key is -1 if the element is not found
1
2
3
4
5
67
89
8
![Page 5: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/5.jpg)
Binary search flow graph1
2
3
4
65
7
while bottom <= top
if (elemArray [mid] == key
(if (elemArray [mid]< key8
9
bottom > top
![Page 6: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/6.jpg)
1, 2, 3, 8, 9 1, 2, 3, 4, 6, 7, 2 1, 2, 3, 4, 5, 7, 2 1, 2, 3, 4, 6, 7, 2, 8, 9 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
Independent paths
![Page 7: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/7.jpg)
Cyclomatic Number
In graph-theoretic terms, the cyclomatic number of a graph G is defined as
C = E – N + 2Pwhere N is the number of nodes E is the number of edges P is the number of connected components (usually, 1)
![Page 8: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/8.jpg)
Cyclomatic Complexity
McCabe suggested that the number C can be used as a source-code metric that reflects the complexity of a program’s control flow
C defines the number of linearly independent paths in a program It can be used as an upper bound for the number of
tests that must be conducted
![Page 9: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/9.jpg)
Alternative Ways to Compute C
There are other ways that can be used to determine the cyclomatic number C C = P + 1
where P is the number of predicate nodes contained in the flow graph
C = Rwhere R is the number of regions into which
the flow graph divides the plane
![Page 10: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/10.jpg)
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
![Page 11: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/11.jpg)
Incremental integration testing
T3
T2
T1
T4
T5
A
B
C
D
T2
T1
T3
T4
A
B
C
T1
T2
T3
A
B
Test sequence1
Test sequence2
Test sequence3
![Page 12: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/12.jpg)
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
![Page 13: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/13.jpg)
Top-down testing
Level 2Level 2Level 2Level 2
Level 1 Level 1Testing
sequence
Level 2stubs
Level 3stubs
. . .
![Page 14: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/14.jpg)
Bottom-up testing
Level NLevel NLevel NLevel NLevel N
Level N–1 Level N–1Level N–1
Testingsequence
Testdrivers
Testdrivers
![Page 15: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/15.jpg)
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
![Page 16: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/16.jpg)
Interface testingTestcases
BA
C
![Page 17: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/17.jpg)
Interfaces types Parameter interfaces
Data passed from one procedure to another
Shared memory interfaces Block of memory is shared between procedures
Procedural interfaces Sub-system encapsulates a set of procedures to be
called by other sub-systems
Message passing interfaces Sub-systems request services from other sub-systems
![Page 18: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/18.jpg)
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
![Page 19: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/19.jpg)
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
![Page 20: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/20.jpg)
Stress testing Exercises the system beyond its maximum design
load. Stressing the system often causes defects to come to light
Stressing the system test failure behaviour.. Systems should not fail catastrophically. Stress testing checks for unacceptable loss of service or data
Particularly relevant to distributed systems which can exhibit severe degradation as a network becomes overloaded
![Page 21: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/21.jpg)
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
Object-oriented testing
![Page 22: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/22.jpg)
Testing levels
Testing operations associated with objects Testing object classes Testing clusters of cooperating objects Testing the complete OO system
![Page 23: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/23.jpg)
Object class testing
Complete test coverage of a class involves Testing all operations associated with an object Setting and interrogating all object attributes Exercising the object in all possible states
Inheritance makes it more difficult to design object class tests as the information to be tested is not localised
![Page 24: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/24.jpg)
Writing A TestCaseimport junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class MoneyTest extends TestCase {
private Money f12CHF; private Money f14CHF; private Money f28USD;
protected void setUp() { f12CHF= new Money(12, "CHF");
f14CHF= new Money(14, "CHF"); f28USD= new Money(28, "USD");
} }
![Page 25: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/25.jpg)
Writing testMethod’spublic void testSimpleAdd() {
Money m12CHF= new Money(12, "CHF"); Money m14CHF= new Money(14, "CHF"); Money expected= new Money(26, "CHF"); Money result= m12CHF.add(m14CHF); assert(expected.equals(result));}
// [12 CHF] + [14 CHF] + [28 USD] == {[26 CHF][28 USD]}public void testMoneyMoneyBag() { Money bag[]= { f26CHF, f28USD }; MoneyBag expected= new MoneyBag(bag);
assertEquals(expected,f12CHF.add(f28USD.add(f14CHF)));
}
![Page 26: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/26.jpg)
TestSuite & Running Tests
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new MoneyTest("testMoneyEquals"));
suite.addTest(new MoneyTest("testSimpleAdd"));
return suite;
}
public static void main(String args[]) { junit.swingui.TestRunner.run(suite());
}
![Page 27: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/27.jpg)
Object integration
Levels of integration are less distinct in object-oriented systems
Cluster testing is concerned with integrating and testing clusters of cooperating objects
Identify clusters using knowledge of the operation of objects and the system features that are implemented by these clusters
![Page 28: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/28.jpg)
Approaches to cluster testing Use-case or scenario testing
Testing is based on a user interactions with the system
Has the advantage that it tests system features as experienced by users
Object interaction testing Tests sequences of object interactions that stop
when an object operation does not call on services from another object
![Page 29: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/29.jpg)
Association – The Bank Client App
BankClientMain BankClientFrame
BankClientConnector
request(String cmd):String
![Page 30: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/30.jpg)
Scenario-based testing
Identify scenarios from use-cases and supplement these with interaction diagrams that show the objects involved in the scenario
Consider the scenario in the weather station system where a report is generated
![Page 31: CSC 480 Software Engineering Lecture 15 Oct 21, 2002.](https://reader036.fdocuments.us/reader036/viewer/2022081603/56649f285503460f94c40b22/html5/thumbnails/31.jpg)
Collect weather data:CommsController
request (report)
acknowledge ()report ()
summarise ()
reply (report)
acknowledge ()
send (report)
:WeatherStation :WeatherData