Sie sind auf Seite 1von 15

Software Testing

Please bring a printed copy, or, if you have a long commute, submit it early enough so I can
print it.
1.
(10) This Spring, we switched to Daylight Savings time on March 7. Officially, this
switch occurred at 2:00 a.m. on Sunday morning, March 8, 2015, when clocks were reset to
3:00 a.m. Suppose you had to test a telephone call billing program that charges all calls
using the following rate structure:
Call Duration <= 20 minutes charged at $0.05 per each minute or fraction of a minute
Call Duration > 20 minutes charged at $1.00 plus $0.10 per each minute or fraction of a
minute in excess of 20 minutes.
Please use variables from this brief data dictionary in your discussion. (Note that I assume
the maximum call duration is 30 hours; this simplifies your analysis.)
Variable
CD
CST

Description
Call Duration
Call start time

Units
hour:min:sec
JulianDay:hour:min:sec

CET
Cost

Call end time


Charge for call

JulianDay:hour:min:sec
US Dollars and cents

Range
0 - 30 hours
1<=JulianDay<=36
6
0<=hour<=23
0<=min<=59
0<=sec<=59
(same as for CST)
max Cost =
$179.00

Make these assumptions:


chargeable time of a call begins when the called party answers, and ends when the
calling party disconnects.
call durations of seconds are rounded up to the next larger minute
no call lasts more than 30 hours
Now for the question: How would you test this portion of the call billing program? Explain
your choice of test method. "Do" your chosen method in the following sense:

if you chose a form of Boundary Value Testing, make a graph of your test cases.

if you chose Equivalence Class Testing, list your classes.


Equivalence classes are best based on the start and end times of a call, then the call
duration is simply end time minus start time, with a possible correction for the switch to
daylight time.

if you chose Decision Table Testing, show your decision table.

2.
(10) Draw the program graph for the call charge procedure pseudocode given
below. What is its cyclomatic complexity?
Procedure callCharge1(cst, cet,cost)
Dim duration As Time
1.
round up seconds on cst
2.
round up seconds on cet
3.
If (cst < 97:02:00:00)'time change for 2015, March 7 (day 66)
4.
Then 'call starts in standard time
5.
If (cet <= 66:02:00)
6.
Then duration = cet - cst
'call ends in standard
time
7.
Else duration = (cet - cst
) - 00:01:00 'call ends in
daylight time
8.
EndIf
9.
Else
'call starts in daylight time
10.
If (cet > 66:03:00)
11.
Then duration = cet - cst
'call ends in daylight
time
12.
Else error message ("call ends in standard time
IMPOSSIBLE")
13.
EndIf
14.
EndIf
15.
If (duration <= 00:00:20)
16.
Then cost = $0.05 * duration
17.
Else cost = $1.00 + $0.10 * (duration - 00:00:20)
18. EndIf
19.
End Procedure callCharge1
3.
(10)
sequence

List distinct paths are in your graph. As a start, the path P1 follows the node
P1 = <1, 2, 3, 4, 5, 6, 8, 14, 15, 16, 18, 19>

4.
(10) Which of the paths you identified in Question 2 are traversed by the test cases
you postulated in Question 1?
5.
(10) E.F. Miller proposed the following test coverage metrics in his Ph.D. dissertation
in the mid-1970s:
C0
Every Statement
C1
Every DD-Path
C1p
Every predicate outcome
C2
C1 plus loop coverage
Cd
C1 plus every dependent pair of DD-Paths
CMCC
Compound condition coverage
Cik
Every program path that contains up to k (usually =2) loop repetitions
Cstat
Statistically significant fraction of paths
C
All possible execution paths
Our revised definition of a program graph mandates changes to some of these. In addition, if
we apply basic concepts of directed graphs, we can define better coverage metrics. Make
use of our definitions of indegree, outdegree, edge, chain, strong component, and path. Use
this definition and notation as a start.
Definition: Given a program P written in an imperative programming language, its program
graph G(P) is a directed graph in which nodes, n i, correspond to statement fragments, and

edges, ei, correspond to possible sequential execution of the statement fragments that mark
the originating and terminating nodes of an edge.
Use your knowledge of directed graphs to define a set of test coverage metrics; for
separation from Millers metrics, name yours Dx. As a start, consider (remember, I do the
easy parts!):
Given a set of test cases T for program P, where G(P) is the program graph of P, when the
set T is run on P, the coverage of T on P is defined by:
D0

Every node in G(P) is traversed.

6.
(5)
Relate your set of Dx coverage metrics to Millers set. (Dont worry about
Cstat .) As a start, you can say
D0 C0
7.

(5)

Here is a lattice of Miller's coverage metrics...

Express your coverage metrics as a lattice, and compare your lattice to the one above.

8. (10) In chapter 10, we defined a program slice as follows:


Given a program P and a set V of variables in P, a slice on the variable set V at statement n,
written S(V, n), is the set of all statement fragments in P that contribute to the values of
variables in V at node n.
Technically, this is a "backward slice" because it refers to statement fragments that
contribute to the value(s) of the variables in statement fragment that corresponds to node n
in the program graph. We can (others have) define a "forward slice" as the set of all nodes in
a program graph that are affected by a variable at statement fragment n.
For your convenience, here is the pseudocode for our Commission Problem and its program
graph.

Make two copies of above example. Use one to show the backward slice of lockSales at node
24. (Just highlight the backward slice). Then use your second copy to show (and highlight)
the forward slice of lockPrice at node 7. Finally highlight the nodes for each of your slices.9.
(5)
Determine the cyclomatic complexity of this graph.

10.
(10)
Instrument the "integration version" of NextDate (begins on the next
page) so that, if the instrumented pseudo-code could be executed, you could find MM-Paths
"automatically". Your instrumentation should show just the message flow (calls and returns)
that you can derive from the pseudo-code. Dont worry about new statement numbers for
your instrumentation, but please, make it easily recognizable (e.g., bold or maybe red font)
Try out your instrumentation for April 22, 2015 (exam due date!). Show what your
instrumentation would print/write to a file.

Main proceduralNextDate
Type Date

'Integration Version
Month As Integer
Day As Integer
Year As Integer

EndType
Dim today As Date
Dim tomorrow As Date
2
3
4
5
6

GetDate(today)
PrintDate(today)
tomorrow = IncrementDate(today)
PrintDate(tomorrow)
End Main

7
8
9
10
11
12
13
14
15
16
17
18
19
20

Function isLeap(year)Boolean
If (year divisible by 4)
Then
If (year is NOT divisible by 100)
Then isLeap = True
Else
If (year is divisible by 400)
Then isLeap = True
Else isLeap = False
EndIf
EndIf
Else isLeap = False
EndIf
End (Function isLeap)

21
22
23
24
25
26
27
28
29
30
31
32
33

Function lastDayOfMonth(month, year)


Integer
Case month Of
Case 1: 1, 3, 5, 7, 8, 10, 12
lastDayOfMonth = 31
Case 2: 4, 6, 9, 11
lastDayOfMonth = 30
Case 3: 2
If (isLeap(year))
Then lastDayOfMonth = 29
Else lastDayOfMonth = 28
EndIf
EndCase
End (Function lastDayOfMonth)

34

Function GetDate(aDate)
Date
dim aDate As Date
Function ValidDate(aDate) Boolean
'within scope of GetDate
dim aDate As Date
dim dayOK, monthOK, yearOK As Boolean

35

36
37
38
39
40

If ((aDate.Month > 0) AND (aDate.Month <=12)


Then monthOK = True
Else monthOK = False
EndIf
If (monthOK)

41
42

Then
If ((aDate.Day > 0) AND

(aDate.Day <=

lastDayOfMonth(aDate.Month, aDate.Year))
43
Then dayOK = True
44
Else dayOK = False
45
EndIf
46
EndIf
47
48
49
50
51
52
53
54
55

If ((aDate.Year > 1811) AND (aDate.Year <= 3012)


Then yearOK = True
Else yearOK = False
EndIf

56
57
58
59
60
61
62
63
64
65
66
67

If (monthOK AND dayOK AND yearOK)


Then ValidDate = True
Else ValidDate = False
EndIf
End (Function ValidDate)
' GetDate body begins here
Do
Output("enter a month")
Input(aDate.Month)
Output("enter a day")
Input(aDate.Day)
Output("enter a year")
Input(aDate.Year)
GetDate.Month = aDate.Month
GetDate.Day = aDate.Day
GetDate.Year = aDate.Year
Until (ValidDate(aDate))
End (Function GetDate)

68
69
70
71
72
73
74
75
76
77
78

Function IncrementDate(aDate)
Date
If (aDate.Day < lastDayOfMonth(aDate.Month))
Then aDate.Day = aDate.Day + 1
Else aDate.Day = 1
If (aDate.Month = 12)
Then aDate.Month = 1
aDate.Year = aDate.Year + 1
Else aDate.Month = aDate.Month + 1
EndIf
EndIf
End (IncrementDate)

79
80
81

Procedure PrintDate(aDate)
Output( "Day is ", aDate.Month, "/", aDate.Day, "/", aDate.Year)
End (PrintDate)

11.
(5)
Explain why you can (or cannot) instrument the integration version to show
points of message quiescence?

12.
(10)
Compute how many mutations will be generated for the Visual Basic
Function isLeap when the following mutation operators are applied to the source code.
Arithemetic Operation Mutator:
Relational Operation Mutator:
Constant Mutator:
Connective Mutator:
Boolean Mutator:
Assignment Mutator
Variable Mutator
Variable Mutator

{+, -, *, /, %}
{<, <=, ==, !=, >=, >}}
{x, x+1, x-1}
{AND, OR, EOR}
{True, False}
{=, +=, -=}
{year, anno, Jahr}
{c1, d1, c2)

Function isLeap(year) Boolean


c1 = (year % 4 == 0)
c2 = (year % 100 == 0)
c3 = (year % 400= = 0)
isLeap = False
If ((c1 AND NOT(c2)) OR (c3)) Then
isLeap = True
EndIf
End Function isLeap
This table/spreadsheet excerpt should help.
Program element
Respective mutations
c1 = (year % 4 ==
0)
c2 = (year % 100
== 0)
c3 = (year % 400
== 0)
isLeap = False
If ((c1 AND NOT(c2))
OR (c3))
isLeap = True

c1

year

c2

year

c3
isLea
p

year
Fals
e

4
10
0
40
0

NOT

c2

OR

c1
isLea
p

=
AN
D
=

True

=
=
=
=
=
=

c3

0
0
0

13. . (10)
formulation:

Develop operational profiles for the garage door controller. Use this

Input events
Output events
(actions)
States
e1: depress controller button
a1: start drive motor down
s1:
Door Up
e2: end of down track hit
a2: start drive motor up
s2: Door Down
e3: end of up track hit
a3: stop drive motor
s3: Door Stopped going down
e4: obstacle hit
a4: reverse motor down to
up s4: Door Stopped going up
e5: laser beam crossed
s5: Door Closing

s6: Door Opening


The transition probabilities are shown in the finite state machine below in parentheses
preceding the usual transition label.

On the next page there is a start to your spreadsheet. I did Use Case 1 for you. Use the use
cases as shown, and then develop the operation profile testing order. Be sure to show your
use case probabilities, and your operational testing order.

Path
/ Use
Case
1

Description

State Sequence

Normal close.

s1, s5, s2
s2, s6, s1

Normal open.
Close, stopped and
restarted.
Close, stopped and
restarted, stopped a second
time, and restarted.
Open, stopped and
restarted.
Open, stopped and
restarted, stopped a second
time, and restarted.
Close, obstacle sensed.

Close, laser beam crossed.

s1, s5, s6 (e5), s1

2
3
4
5
6

10

Close, stopped and


restarted, obstacle sensed,
stopped opening, restarted
Close, stopped and
restarted, laser beam
crossed stopped opening,
restarted

s1, s5, s3, s5, s2


s1, s5, s3, s5, s3, s5, s2
s2, s6, s4, s6, s1
s2, s6, s4, s6, s4, s6,
s1
s1, s5, s6 (e4), s1

s1, s5, s3, s5, s6 (e4),


s1
s1, s5, s3, s5, s6 (e5),
s1

path
probabilit
y
0.8500

14.
(8)
This is an extension of the Garage Door Controller problem. The two safety
devices (light beam and obstacle sensor) can fail. Here we consider two common failure
modes: stuck at one and stuck at zero. Failure Mode Effects Analysis (FMEA) is a widely
accepted way to deal with such situations. The table below describes the effects of the
"stuck at" failure modes for each device. Each device is enabled when the garage door
begins to close. In normal operation, the devices are disabled when the garage door stops,
either partially or fully closed.
Enabled Safety
Device
Light Beam Sensor

Stuck at zero

Stuck at one

does not send a signal


when the light beam is
interrupted

Obstacle Sensor

does not send a signal


when an obstacle is
encountered

always sends a signal, even


when
there is no light beam
interruption
always sends a signal, even
when
no obstacle is sensed

The hope of designers is that the safety devices never fail. The lawyers, however, have a
more cautious view, and correctly worry about lawsuits due to device malfunctions. For this
question, add your completed use cases to the operational profiles you developed for the
original ten use cases given earlier Take a closer look at the failure modes. We will postulate
four new events that can occur in state s5: Door Closing
e6: Obstacle encountered, sensor stuck at zero
e7: Obstacle sensor stuck at one
e8: Light beam interrupted, sensor stuck at zero
e9: Light beam sensor stuck at one
Complete the four new use cases, started here. Add additional rows for events if you need
them, and be sure to show the post-conditions.

Name, ID
Description
Preconditions

Door close with Obstacle Sensor


stuck at zero
FMEA UC-11
A fully open door begins to close with a control device signal. An
obstacle is encountered, but no signal is sent
Garage door is open
Event Sequence
Inputs
Outputs
1 e1: control device signal
2. a1: start drive motor down
3 e6: Obstacle encountered,
sensor stuck at zero

Postconditions

Name, ID
Description
Pre-

Door close with Obstacle Sensor


stuck at one
FMEA UC-12
A fully open door begins to close with a control device signal. The
obstacle sensor immediately sends a signal.
Garage door is open

conditions
Event Sequence
Inputs
Outputs
1 e1: control device signal
2. a1: start drive motor down
3. e7: Obstacle sensor stuck at
one
Postconditions

Name, ID
Description
Preconditions

Door close with Light Beam


Sensor
stuck at zero
FMEA UC-13
A fully open door begins to close with a control device signal.
Something interrupts the light beam, but no signal is sent
Garage door is open
Event Sequence
Inputs
Outputs
1 e1: control device signal
2. a1: start drive motor down
3. e8: Light beam interrupted,
sensor stuck at zero

Postconditions

Name, ID
Description
Preconditions

Door close with Light Beam


Sensor
stuck at one
FMEA UC-14
A fully open door begins to close with a control device signal. The
light beam sensor immediately sends a signal.
Garage door is open
Event Sequence
Inputs
Outputs
1 e1: control device signal
2. a1: start drive motor down
3. e9: Light beam sensor stuck at
one

Postconditions

15.
(12)
Device failure rates are usually very small. For this exercise, assume
that both the light beam sensor and the obstacle sensor have total failure rates of 0.0001;
stuck at 0 failures are more common than stuck at 1 failures. The four new events will have
VERY LOW probabilities, and these are given in the Table 12.1 below:
Table 12.1: "Stuck at" Probabilities
for the Safety Devices
Device
Stuck at 0
Stuck at 1
probability
probability
Obstacle Sensor
0.00006
0.00004
Light Beam Sensor
0.00008
0.00002
This is where the lawyers enter the picture. If a closing door fails to close when it should, the
garage might be left open for an entire working day, leaving the home vulnerable to massive
thefts, vandalism, or some other calamity. Similarly, if the garage door does not close when
it should, a pet, a child, or possibly some very fragile (and expensive) artifact could be
damaged. Any of these calamities would likely result in a very expensive lawsuit. This
question asks you to extend your operational profiles from question 11 to Risk-Based
Testing. To help with this, I provide the cost of failure penalties for each of the 12 use cases.
Add your completed use cases to the Operational Profiles you developed for Question 10,
and then use the given cost of failure penalties to produce the Risk-Based Testing profile.
Use cases 6 through 10 are replaced by the your new use cases. The (deliberately)
incomplete figure below may help you develop your path probabilities. Notice the new
transition probabilities, and the probabilities you need to add. (Note the new path
probabilities.)

Table 12.2 Operational Profiles for the Garage Door Controller (with FMEA use cases)

Path /
Use
Case
1
2
3
4
5

Description

State Sequence

Normal close.

s1, s5, s2

Normal open.
Close, stopped and
restarted.
Close, stopped and
restarted, stopped a
second time, and
restarted.
Open, stopped and
restarted.

s2, s6, s1
s1, s5, s3, s5, s2

path
probability
0.9400

Cost of
Failure
$600.
$100.
$600.

s1, s5, s3, s5, s3,


s5, s2
$600.
s2, s6, s4, s6, s1

11

Door close with Obstacle


Sensor stuck at zero

s1, s5, ??????

12

Door close with Obstacle


Sensor stuck at one

s1, s5, ??????

13

Door close with Light


Beam Sensor stuck at
zero

s1, s5, ??????

14

Door close with Light


Beam Sensor stuck at one

s1, s5, ??????

$100.
$600.
$200,000,00
0.
$600.
$300,000,00
0.

Point values of questions


Question
Points
1

10

10

10

10

10

10

10

10

11

12

10

13

10

14

15

12

your score

Das könnte Ihnen auch gefallen