N this chapter, we will introduce you to the fundamentals of testing: why testing is


partitions and boundaries.) Derive test cases for the partitions and boundaries



tải về 6.34 Mb.
Chế độ xem pdf
trang19/25
Chuyển đổi dữ liệu03.04.2023
Kích6.34 Mb.
#54490
1   ...   15   16   17   18   19   20   21   22   ...   25
Foundations of Software Testing ISTQB Certification 3rd ed


partitions and boundaries.) Derive test cases for the partitions and boundaries.
Are there any questions you have about this
‘requirement’? Is anything unclear?
Decision table exercise
Scenario: If you hold an ‘over 60s’ rail card, you get a 34% discount on whatever ticket you buy. If you are
travelling with a child (under 16), you can get a 50% discount on any ticket if you hold a family rail card,
otherwise you get a 10% discount. You can only hold one type of rail card.
Produce a decision table showing all the combinations of fare types and resulting discounts and derive test
cases from the decision table.
State transition exercise
Scenario: A website shopping basket starts out as empty. As purchases are selected, they are added to the
shopping basket. Items can also be removed from the shopping basket. When the customer decides to check out,
a summary of the items in the basket and the total cost are shown, for the customer to say whether this is OK or
not. If the contents and price are OK, then you leave the summary display and go to the payment system.
Otherwise you go back to shopping (so you can remove items if you want).
a. Produce a state diagram showing the different states and transitions. Define a test, in terms of the sequence of
states, to cover all transitions.
b. Produce a state table. Give an example test for an invalid transition.
Statement and decision testing exercise
Scenario: A vending machine dispenses either hot or cold drinks. If you choose a hot drink (e.g. tea or coffee), it
asks if you want milk (and adds milk if required), then it asks if you want sugar (and adds sugar if required), then
your drink is dispensed.
a. Draw a control flow diagram for this example. (Hint: regard the selection of the type of drink as one
statement.)
b. Given the following tests, what is the statement coverage achieved? What is the decision coverage achieved?
Test 1: Cold drink
Test 2: Hot drink with milk and sugar
c. What additional tests would be needed to achieve 100% statement coverage? What additional tests would be
needed to achieve 100% decision coverage?
Exercises: Test Design Techniques 115


E X E R C I S E S O L U T I O N S
EP/BVA exercise
The first thing to do is to establish exactly what the boundaries are between the full fare and saver fare. Let
’s put
these in a table to organize our thoughts:
Scheduled departure time
% 9:29 am
9:30 am
– 4:00 pm
4:01 pm
– 7:30 pm
^ 7:31 pm
Ticket type
full
saver
full
saver
We have assumed that the boundary values are: 9:29 am, 9:30 am, 4:00 pm, 4:01 pm, 7:30 pm and 7:31 pm.
By setting out exactly what we think is meant by the specification, we may highlight some ambiguities or, at
least, raise some questions
– this is one of the benefits of using the technique! For example:
‘When does the morning rush hour start? At midnight? At 11:30 pm the previous day? At the time of the first
train of the day? If so, when is the first train? 5:00 am?

This is a rather important omission from the specification. We could make an assumption about when it starts,
but it would be better to find out what is correct.
l
If a train is due to leave at exactly 4:00 pm, is a saver ticket still valid?
l
What if a train is due to leave before 4:00 pm but is delayed until after 4:00 pm? Is a saver ticket still valid?
(i.e. if the actual departure time is different to the scheduled departure time.)
Our table above has helped us to see where the partitions are. All of the partitions in the table above are valid
partitions. It may be that an invalid partition would be a time that no train was running, e.g. before 5:00 am, but
our specification didn
’t mention that! However it would be good to show this possibility also. We could be a bit
more formal by listing all valid and invalid partitions and boundaries in a table, as we described in Section 4.3.1,
but in this case it doesn
’t actually add a lot, since all partitions are valid.
Here are the test cases we can derive for this example:
Test case reference
Input
Expected outcome
1
Depart 4:30 am
Pay full fare
2
Depart 9:29 am
Pay full fare
3
Depart 9:30 am
Buy saver ticket
4
Depart 11:37 am
Buy saver ticket
5
Depart 4:00 pm
Buy saver ticket
6
Depart 4:01 pm
Pay full fare
7
Depart 5:55 pm
Pay full fare
8
Depart 7:30 pm
Pay full fare
9
Depart 7:31 pm
Buy saver ticket
10
Depart 10:05 pm
Buy saver ticket
Note that test cases 1, 4, 7 and 10 are based on equivalence partition values; test cases 2, 3, 5, 6, 8 and 9 are
based on boundary values. There may also be other information about the test cases, such as preconditions, that
we have not shown here.
116
Chapter 4 Test design techniques


Decision table exercise
The fare types mentioned include an
‘over 60s’ rail card, a family rail card, and whether you are travelling with a
child or not. With three conditions or causes, we have eight columns in our decision table below.
Causes (inputs)
R1
R2
R3
R4
R5
R6
R7
R8
over 60s rail card?
Y
Y
Y
Y
N
N
N
N
family rail card?
Y
Y
N
N
Y
Y
N
N
child also travelling?
Y
N
Y
N
Y
N
Y
N
Effects (outputs)
Discount (%)
X/?/50%
X/?/34%
34%
34%
50%
0%
10%
0%
When we come to fill in the effects, we may find this a bit more difficult. For the first two rules, for example,
what should the output be? Is it an X because holding more than one rail card should not be possible? The
specification doesn
’t actually say what happens if someone does hold more than one card, i.e. it has not specified
the output, so perhaps we should put a question mark in this column. Of course, if someone does hold two rail
cards, they probably wouldn
’t admit this, and perhaps they would claim the 50% discount with their family rail
card if they are travelling with a child, so perhaps we should put 50% for Rule 1 and 34% for Rule 2 in this
column. Our notation shows that we don
’t know what the expected outcome should be for these rules!
This highlights the fact that our natural language (English) specification is not very clear as to what the effects
should actually be. A strength of this technique is that it forces greater clarity. If the answers are spelled out in a
decision table, then it is clear what the effect should be. When different people come up with different answers
for the outputs, then you have an unclear specification!
The word
‘otherwise’ in the specification is ambiguous. Does ‘otherwise’ mean that you always get at least a
10% discount or does it mean that if you travel with a child and an over 60s card but not a family card you get
10% and 34%? Depending on what assumption you make for the meaning of
‘otherwise’, you will get a different
last row in your decision table.
Note that the effect or output is the same (34%) for both Rules 3 and 4. This means that our third cause
(whether or not a child is also travelling) actually has no influence on the output. These columns could therefore
be combined with
‘don’t care’ as the entry for the third cause. This ‘rationalizing’ of the table means we will
have fewer columns and therefore fewer test cases. The reduction in test cases is based on the assumption we are
making about the factor having no effect on the outcome, so a more thorough approach would be to include each
column in the table.
Here is a rationalized table, where we have shown our assumptions about the first two outcomes and we
have also combined Rules 6 and 8 above, since having a family rail card has no effect if you are not travelling
with a child.
Causes (inputs)
R1
R2
R3
R5
R6
R7
over 60s rail card?
Y
Y
Y
N
N
N
family rail card?
Y
Y
N
Y

N
child also travelling?
Y
N

Y
N
Y
Effects (outputs)
Discount (%)
50%
34%
34%
50%
0%
10%
Exercise Solutions 117


Here are the test cases that we derive from this table. (If you didn
’t rationalize the table, then you will have
eight test cases rather than six.) Note that you wouldn
’t necessarily test each column, but the table enables you to
make a decision about which combinations to test and which not to test this time.
Test case reference Input
Expected outcome
1
S. Wilkes, with over 60s rail card and family rail card, travelling
with grandson Josh (age 11)
50% discount for both tickets
2
Mrs. M. Davis, with over 60s rail card and family rail card,
travelling alone
34% discount
3
J. Rogers, with over 60s rail card, travelling with his wife
34% discount (for J. Rogers
only, not the wife)
4
S. Gray, with family rail card, travelling with her daughter Betsy 50% discount for both tickets
5
Miss Congeniality, no rail card, travelling alone
No discount
6
Joe Bloggs with no rail card, travelling with his 5-year-old niece 10% discount for both tickets
Note that we may have raised some additional issues when we designed the test cases. For example, does the
discount for a rail card apply only to the traveller or to someone travelling with them? Here we have assumed that
it applies to all travellers for the family rail card, but to the individual passenger only for the over 60s rail card.
State transition exercise
The state diagram is shown in Figure 4.7. The initial state (S1) is when the shopping basket is empty. When an
item is added to the basket, it goes to state (S2), where there are potential purchases. Any additional items added
to the basket do not change the state (just the total number of things to purchase). Items can be removed, which
does not change the state unless the total items ordered goes from 1 to 0. In this case, we go back to the empty
basket (S1). When we want to check out, we go to the summary state (S3) for approval. If the list and prices are

tải về 6.34 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   15   16   17   18   19   20   21   22   ...   25




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương