Oo
Oo
Oo
Cheung
HKUST
CSIT5100
Object-Oriented Software
Development of Enterprise Systems
!o is t!is co"rse for#
If you can answer yes to:
G
abstraction is always for some purpose
G
many different abstractions of the same thing are possible
G
all abstractions are incomplete descriptions of reality
We do not need completeness, just modeling adequacy!
flies,
CSIT*+,, ++ scc
+3 roads.
-3 &and topo&ogy 2e.g.; contours showng e&evaton
a%ove sea &eve&.
.3 hstorca& stes to see 2e.g.; the HKUST %each3.
/3 the types and p&aces of vegetaton 2.e.; trees
and other types of p&ants3.
*3 &ocaton of h)ng tra&s.
13 %us routes.
If you had to draw a map of the area around HKUST to e:p&an to
someone how to get to HKUST from Cho Hung; what s the one most
mportant thng you wou&d nc&ude!
.'ESTIO&#
CSIT*+,, +- scc
+3 roads.
-3 &and topo&ogy 2e.g.; contours showng
e&evaton a%ove sea &eve&.
.3 hstorca& stes to see 2e.g.; the HKUST
%each3.
/3 the types and p&aces of vegetaton 2.e.;
trees and other types of p&ants3.
*3 &ocaton of h)ng tra&s.
13 %us routes.
If you had to draw a map of the area around HKUST to e:p&an to someone
how hgh the <cademc =u&dng s a%ove sea &eve&; what s the one most
mportant thng you wou&d nc&ude!
.'ESTIO&#
CSIT*+,, +. scc
+,ST-+CTIO&S
publics#a#icvoi%main(7trin
gargsPQ#K
7ystem.out.print$n(2actoria$("
##N
O
O
Liang, Introduction to Java Programming
9ow is t%e code
structured6
(%at goes in a c$ass6
met%ods
Adapted by S.C. Cheung 33
publicclassIactoria$ K
publics#a#icin#2actoria$(in
#n#K
i$(nLM1#re#urn1N
re#urn2actoria$(n!1#FnN
O
publics#a#icvoi%main(7trin
gargsPQ#K
7ystem.out.print$n(2actoria$("
##N
O
O
Liang, Introduction to Java Programming
9ow is t%e code
structured6
(%at goes in a
met%od6
statements
Adapted by S.C. Cheung 3+
publicclassIactoria$ K
publics#a#icin#2actoria$(in
#n#K
i$(nLM1#re#urn1N
re#urn2actoria$(n!1#FnN
O
publics#a#icvoi%main(7trin
gargsPQ#K
7ystem.out.print$n(2actoria$("
##N
O
O
Liang, Introduction to Java Programming
Adapted by S.C. Cheung 3,
Iurt%er *natomy
!
Comments
!
Pac1age
!
>eserved words
!
T%e main met%od
Liang, Introduction to Java Programming
Adapted by S.C. Cheung 3-
Comments
In Java, comments are preceded by=
!
two s$as%es (EE# in a $ine, or
!
enc$osed between EF and FE in one or
mu$tip$e $ines.
(%en t%e compi$er sees EE, it ignores a$$ te&t
a2ter EE in t%e same $ine.
(%en it sees EF, it scans 2or t%e ne&t FE and
ignores any te&t between EF and FE.
Liang, Introduction to Java Programming
Adapted by S.C. Cheung 33
Pac1age
T%e <rst $ine in t%e program (pac1age introN#
speci<es a pac1age name, intro, 2or t%e c$ass
/$
$ %actorial&ava
$/
package intro"
public class %actorial
{
public static int 'actorial( int n ) {
if ( n ()* ) return *"
return 'actorial( n+* ) $ n"
#
public static void main(String args[]){
Systemoutprintln ( 'actorial ( , ) )"
#
#
Liang, Introduction to Java Programming
Adapted by S.C. Cheung 31
main :et%od
T%e main met%od provides t%e contro$ o2
program Cow. Java virtua$ mac%ine starts
e&ecuting a program 2rom its main met%od.
%xte"sive hardware#software
%xte"sive hardware#software
i"tegratio" re!uires more testi"g
i"tegratio" re!uires more testi"g
Youre going to spend about half of
Youre going to spend about half of
your development budget on testing,
your development budget on testing,
whether you want to or not.
whether you want to or not.
May 8, 2014 CSIT5100 5
Mi%rosoft &'(#ishes !in)ows
*& +'g ,ist!!
&irosoft today published the full bug list for its &irosoft today published the full bug list for its
'i"dows () operati"g system* +or the first time ever, 'i"dows () operati"g system* +or the first time ever,
all k"ow" a"d reported bugs are to be made available all k"ow" a"d reported bugs are to be made available
to the publi* to the publi*
&r* ,ya"#-ee of .orea /photographed above0 made the &r* ,ya"#-ee of .orea /photographed above0 made the
mistake of pri"ti"g the whole list 11* mistake of pri"ti"g the whole list 11*
May 8, 2014 CSIT5100 -
In%i)ents of Software .ai#'res
2ria"e 3 Its maide" flight o" 4u"e 4, 1556 e"ded i" the lau"her bei"g 2ria"e 3 Its maide" flight o" 4u"e 4, 1556 e"ded i" the lau"her bei"g
exploded beause of a hai" of software failures exploded beause of a hai" of software failures
-o"do" 2mbula"e 7eause of a suessio" of software e"gi"eeri"g -o"do" 2mbula"e 7eause of a suessio" of software e"gi"eeri"g
failures, espeially defets i" pro8et ma"ageme"t, a system was failures, espeially defets i" pro8et ma"ageme"t, a system was
i"trodued that failed twie i" the autum" of 1559* 2lthough the i"trodued that failed twie i" the autum" of 1559* 2lthough the
mo"etary ost, at :o"ly; about <5m, was small by ompariso" with other mo"etary ost, at :o"ly; about <5m, was small by ompariso" with other
examples, it is believed that people died who would "ot have died if examples, it is believed that people died who would "ot have died if
ambula"es had reahed them as promptly as they would have do"e ambula"es had reahed them as promptly as they would have do"e
without this software failure* without this software failure*
Thera#93 7etwee" 15=3 a"d 15=7 six people /at least0 suffered serious Thera#93 7etwee" 15=3 a"d 15=7 six people /at least0 suffered serious
radiatio" overdoses beause of software#related malfu"tio"s of the radiatio" overdoses beause of software#related malfu"tio"s of the
Thera#93 radiatio" therapy mahi"e* Three of them are thought to have Thera#93 radiatio" therapy mahi"e* Three of them are thought to have
died of the overdoses* 2" importa"t root ause was a lak of !uality died of the overdoses* 2" importa"t root ause was a lak of !uality
assura"e, whih led to a" over#omplex, i"ade!uately tested, assura"e, whih led to a" over#omplex, i"ade!uately tested,
u"der#doume"ted system bei"g developed, a"d subse!ue"tly to the u"der#doume"ted system bei"g developed, a"d subse!ue"tly to the
failure to take ade!uate orretive atio"* failure to take ade!uate orretive atio"*
-o"do" >tok %xha"ge Taurus was a pla""ed automated tra"satio" -o"do" >tok %xha"ge Taurus was a pla""ed automated tra"satio"
settleme"t system* The pro8et was a"eled i" 1553 after havi"g settleme"t system* The pro8et was a"eled i" 1553 after havi"g
lasted more tha" five years a"d osti"g arou"d <73m? the estimated lasted more tha" five years a"d osti"g arou"d <73m? the estimated
loss to ustomers was arou"d <430m? a"d the damage to the reputatio" loss to ustomers was arou"d <430m? a"d the damage to the reputatio"
of the -o"do" >tok %xha"ge was i"alulable* of the -o"do" >tok %xha"ge was i"alulable*
May 8, 2014 CSIT5100 /
0n In%i)ent in Hong 1ong
'e are goi"g through a time of ha"ge 'e are goi"g through a time of ha"ge
networ" routers
financial networ"s
other infrastructure
airplanes
#$%& systems
Sensor'enabled systems
Cellular phones
2"d of ourse 1 'e wa"t 'hatsapp a"d Ga"dy Gru"h 2"d of ourse 1 'e wa"t 'hatsapp a"d Ga"dy Gru"h
"ot to rash i" the middle! "ot to rash i" the middle!
Testing ideas have
Testing ideas have
matured enough to
matured enough to
be used in practice
be used in practice
May 8, 2014 CSIT5100 2
Software )eve#o34ent a%tivities
an) testing #eve#s
May 8, 2014 CSIT5100 10
I43ortant Ter4s
5a#i)ation 6 5eri7%ation
IHIH sta"ds for :i"depe"de"t verifiatio" IHIH sta"ds for :i"depe"de"t verifiatio"
a"d validatio"; a"d validatio";
May 8, 2014 CSIT5100 11
Stati% an) 8yna4i% Testing
>tati Testi"g
>tati Testi"g
E Testi"g without
E Testi"g without
exeuti"g the program*
exeuti"g the program*
@y"ami Testi"g
@y"ami Testi"g
E Testi"g by exeuti"g
E Testi"g by exeuti"g
the program with real i"puts
the program with real i"puts
May 8, 2014 CSIT5100 12
Software .a'#ts, 9rrors 6
.ai#'res
>oftware +ault >oftware +ault E E 2 stati defet i" the software 2 stati defet i" the software
>oftware %rror >oftware %rror E 2" i"orret i"ter"al state E 2" i"orret i"ter"al state
that is the ma"ifestatio" of some fault that is the ma"ifestatio" of some fault
>oftware +ailure >oftware +ailure E %xter"al, i"orret behavior E %xter"al, i"orret behavior
with respet to the re!uireme"ts or other with respet to the re!uireme"ts or other
desriptio" of the expeted behavior desriptio" of the expeted behavior
Faults in software are design mistakes and will always exist Faults in software are design mistakes and will always exist
May 8, 2014 CSIT5100 1
I##'strative 9:a43#e
publi stati i"t "umJero /i"tKL x0 M publi stati i"t "umJero /i"tKL x0 M
FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio" FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio"
FF else retur" the "umber of ourre"es of 0 i" x FF else retur" the "umber of ourre"es of 0 i" x
i"t ou"t N 0? i"t ou"t N 0?
for /i"t i N 1? i P x*le"gth? iQQ0 M for /i"t i N 1? i P x*le"gth? iQQ0 M
if /xKiL NN 00 M if /xKiL NN 00 M
ou"tQQ? ou"tQQ?
R R
R R
retur" ou"t? retur" ou"t?
R R
May 8, 2014 CSIT5100 14
I##'strative 9:a43#e ;
Software .a'#t
publi stati i"t "umJero /i"tKL x0 M publi stati i"t "umJero /i"tKL x0 M
FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio" FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio"
FF else retur" the "umber of ourre"es of 0 i" x FF else retur" the "umber of ourre"es of 0 i" x
i"t ou"t N 0? i"t ou"t N 0?
for /i"t i N for /i"t i N 1 1? i P x*le"gth? iQQ0 M ? i P x*le"gth? iQQ0 M
if /xKiL NN 00 M if /xKiL NN 00 M
ou"tQQ? ou"tQQ?
R R
R R
retur" ou"t? retur" ou"t?
R R
May 8, 2014 CSIT5100 15
I##'strative 9:a43#e ;
Software 9rror
publi stati i"t "umJero /i"tKL x0 M publi stati i"t "umJero /i"tKL x0 M
FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio" FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio"
FF else retur" the "umber of ourre"es of 0 i" x FF else retur" the "umber of ourre"es of 0 i" x
i"t ou"t N 0? i"t ou"t N 0?
for /i"t i N for /i"t i N 1 1? i P x*le"gth? iQQ0 M ? i P x*le"gth? iQQ0 M
if /xKiL NN 00 M if /xKiL NN 00 M
ou"tQQ? ou"tQQ?
R R
R R
retur" ou"t? retur" ou"t?
R R
numZero([2, 7, 0])
Any failure occur
Any error occur
May 8, 2014 CSIT5100 1-
I##'strative 9:a43#e ;
Software 9rror
publi stati i"t "umJero /i"tKL x0 M publi stati i"t "umJero /i"tKL x0 M
FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio" FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio"
FF else retur" the "umber of ourre"es of 0 i" x FF else retur" the "umber of ourre"es of 0 i" x
i"t ou"t N 0? i"t ou"t N 0?
for /i"t i N for /i"t i N 1 1? i P x*le"gth? iQQ0 M ? i P x*le"gth? iQQ0 M
if /xKiL NN 00 M if /xKiL NN 00 M
ou"tQQ? ou"tQQ?
R R
R R
retur" ou"t? retur" ou"t?
R R
numZero([2, 7, 0])
Any failure occur
Any error occur
!tate error occurs at t"e first iteration w"ere t"e state is (x#[2,7,0],
count#0, i#$, %&#if)' ("e correct state s"ould )e (x#[2,7,0], count#0,
i#0, %&#if)'
May 8, 2014 CSIT5100 1/
I##'strative 9:a43#e ;
Software 9rror
publi stati i"t "umJero /i"tKL x0 M publi stati i"t "umJero /i"tKL x0 M
FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio" FF %ffetsE if x NN "ull throw Oull)oi"ter%xeptio"
FF else retur" the "umber of ourre"es of 0 i" x FF else retur" the "umber of ourre"es of 0 i" x
i"t ou"t N 0? i"t ou"t N 0?
for /i"t i N for /i"t i N 1 1? i P x*le"gth? iQQ0 M ? i P x*le"gth? iQQ0 M
if /xKiL NN 00 M if /xKiL NN 00 M
ou"tQQ? ou"tQQ?
R R
R R
retur" ou"t? retur" ou"t?
R R
numZero([0, 7, 2])
Any failure occur
Any error occur
Can yo' thin< of a 3rogra4
e:a43#e an) a test %ase that
triggers a fa'#t ('t %a'ses no error
an) fai#'re$
May 8, 2014 CSIT5100 18
int s*uare (int x) +
int result # x , x-
return result-
.
(est case/ s*uare(2)
May 8, 2014 CSIT5100 12
Testing 6 8e('gging
Testi"g
Testi"g
E +i"di"g i"puts that ause
E +i"di"g i"puts that ause
the software to fail
the software to fail
@ebuggi"g
@ebuggi"g
E The proess of fi"di"g a
E The proess of fi"di"g a
fault give" a failure
fault give" a failure
May 8, 2014 CSIT5100 20
.a'#t 6 .ai#'re Mo)e#
Three o"ditio"s "eessary for a failure
Three o"ditio"s "eessary for a failure
to our
to our
1* 1*
$eahability
$eahability
E The loatio" or
E The loatio" or
loatio"s i" the program that o"tai"
loatio"s i" the program that o"tai"
the fault must be reahed
the fault must be reahed
9* 9*
I"fetio"
I"fetio"
E The state of the program
E The state of the program
must be i"orret
must be i"orret
3* 3*
)ropagatio"
)ropagatio"
E The i"feted state must
E The i"feted state must
propagate to ause some output of the
propagate to ause some output of the
program to be i"orret
program to be i"orret
May 8, 2014 CSIT5100 21
Test Case =>Test Case 5a#'es ?
9:3e%te) @es'#tsA
Test Gase Halues Test Gase Halues E The i"put values E The i"put values
"eessary to omplete the i"te"ded "eessary to omplete the i"te"ded
program exeutio" of a test ase* program exeutio" of a test ase*
%xpeted $esults %xpeted $esults E The result that will E The result that will
be produed whe" exeuti"g the test if be produed whe" exeuti"g the test if
the program satisfies its i"te"ded the program satisfies its i"te"ded
behavior* behavior*
Test >et Test >et E 2 set of test ases* E 2 set of test ases*
Test >ript Test >ript E 2 test ase that is E 2 test ase that is
prepared i" a form for automati prepared i" a form for automati
exeutio"* exeutio"*
May 8, 2014 CSIT5100 22
O(serva(i#ity an)
Contro##a(i#ity
Top#@ow" Testi"g
Top#@ow" Testi"g
E Test the
E Test the
mai" proedure, the" go dow"
mai" proedure, the" go dow"
through proedures it alls
through proedures it alls
7ottom#Tp Testi"g
7ottom#Tp Testi"g
E Test the leaves i"
E Test the leaves i"
the tree /proedures that make "o
the tree /proedures that make "o
alls0, a"d move up to the root*
alls0, a"d move up to the root*
7lak#box testi"g 7lak#box testi"g E @erivi"g tests from E @erivi"g tests from
exter"al desriptio"s of the software, exter"al desriptio"s of the software,
i"ludi"g speifiatio"s, re!uireme"ts, a"d i"ludi"g speifiatio"s, re!uireme"ts, a"d
desig" desig"
'hite#box testi"g 'hite#box testi"g E @erivi"g tests from the E @erivi"g tests from the
soure ode i"ter"als of the software, soure ode i"ter"als of the software,
speifially i"ludi"g bra"hes, i"dividual speifially i"ludi"g bra"hes, i"dividual
o"ditio"s, a"d stateme"ts o"ditio"s, a"d stateme"ts
Alternati0e 0iew/ Alternati0e 0iew/ At which level of abstraction to derive tests At which level of abstraction to derive tests
May 8, 2014 CSIT5100 25
C#assi7%ation of Testing
Tailored toE
Tailored toE
-imitatio"sE
-imitatio"sE
Test $e!uireme"ts Test $e!uireme"ts E >peifi software eleme"ts E >peifi software eleme"ts
that a test ase must satisfy or over that a test ase must satisfy or over
Test Griterio" Test Griterio" E 2 olletio" of rules a"d a E 2 olletio" of rules a"d a
proess that defi"e test re!uireme"ts proess that defi"e test re!uireme"ts
A tester6s 7o) is sim2le / Define a model of the
software, then find ways
to cover it
(esting researc"ers "a0e defined do8ens of criteria, )ut t"ey (esting researc"ers "a0e defined do8ens of criteria, )ut t"ey
are all really 7ust a few criteria on four ty2es of structures 9 are all really 7ust a few criteria on four ty2es of structures 9
May 8, 2014 CSIT5100 22
Test Coverage Criteria =+ran%h
CoverageA
%ah subrouti"e
%ah subrouti"e
i"voatio" is a
i"voatio" is a
test
test
re!uireme"t*
re!uireme"t*
Griterio" that
Griterio" that
imposes all
imposes all
these test
these test
re!uireme"ts o"
re!uireme"ts o"
a test set is
a test set is
Uall overageV*
Uall overageV*
May 8, 2014 CSIT5100 1
Test Coverage Criteria
=State4ent CoverageA
$2<;7
$=>=<;7
("is gra2" may re2resent
statements @ )ranc"es
met"ods @ calls
com2onents @ signals
$2<;7
$=>=<7
%at"
Cover every path
$2<;7
$2<7
$=<;7
$=<7
$=>=<;7
$=>=<7 9
May 8, 2014 CSIT5100 4 34
Befs @ 5ses %airs
(x, $, ($,2)), (x, $, ($,=))
$2<;7
$=>=<7
All 5ses
Every def reaches every
use
$2<;7
$2<7
$=<;7
$=<7
$=>=<7
May 8, 2014 CSIT5100 5 35
1G Era3h - .SM 9:a43#e
Me4ory Seats in a ,e:'s 9S
00
Bri0er $
&onfiguration
Bri0er 2
&onfiguration
[Ignition = off] | Button2
[Ignition = off] | Button1
4odified
&onfiguration
sideMirrors () [Ignition = on] |
lumbar () [Ignition = on] |
seatBottom () [Ignition = on] |
seatBack () [Ignition = on] |
?ew
&onfiguration
Bri0er $
?ew
&onfiguration
Bri0er 2
[Ignition = on] | Reset AND Button1
[Ignition = on] | Reset AND Button2
Ignition = off
Ignition = off
(to Modified)
:uard (safety constraint)
(rigger (in2ut)
May 8, 2014 CSIT5100 - 36
2G ,ogi%a# 9:3ressions
( (a > b) or G ) and (x < y)
(ransitions
!oftware !2ecifications
%rogram Becision !tatements
Cogical
Ax2ressions
May 8, 2014 CSIT5100 / 37
2G ,ogi%a# 9:3ressions
)rediate Goverage )rediate Goverage E %ah prediate must be E %ah prediate must be
true a"d false true a"d false
Glause Goverage Glause Goverage E %ah lause must be true E %ah lause must be true
a"d false a"d false
G 3 True) $alse
Active Clause Coverage4 *ach clause must determine the predicate5s result
( (a > b) or G ) and (x < y)
May 8, 2014 CSIT5100 8
38
2G ,ogi% ; 0%tive C#a'se
Coverage
( (a > b) or G ) and (x < y)
1 T F T
2 F F T
du2licate
3 F T T
4 F F T
5 T T T
6 T T F
Dit" t"ese 0alues
for : and (xEy),
(aF)) determines
t"e 0alue of t"e
2redicate
May 8, 2014 CSIT5100 2
G In3't 8o4ain
Chara%teriHation
@esribe the
@esribe the
i"put domai"
i"put domai"
of the software
of the software
>ystem level
>ystem level
T"it level
T"it level
Tests
& (./, 0), & (0, +0), & (, -0), & (+, 0), & (/, +0)
May 8, 2014 CSIT5100 40
4G Synta%ti% Str'%t'res
7ased o" a
7ased o" a
grammar
grammar
, or other
, or other
sy"tati defi"itio"
sy"tati defi"itio"
)rimary example is
)rimary example is
mutatio" testi"g
mutatio" testi"g
=. %nduce small changes to the program4 mutants
>. $ind tests that cause the mutant programs to fail4 "illing
mutants
?. $ailure is defined as different output from the original program
@. Chec" the output of useful tests on the original program
&ead code
Thus, 100W overage is Thus, 100W overage is impossible impossible i" i"
pratie pratie
!u22ose t"at (G consists
of fi0e test re*uirement,
eac" re2resented in a
different color'
May 8, 2014 CSIT5100 44
Two !ays to Bse Test Criteria
1* 1* @iretly ge"erate @iretly ge"erate test values test values to satisfy to satisfy the the
riterio" riterio"
sometimes misleading
7oth problems are provably 7oth problems are provably u"deidable u"deidable for for
most riteria most riteria
Goverage a"alysis tools Goverage a"alysis tools are !uite ple"tiful are !uite ple"tiful
May 8, 2014 CSIT5100 4-
Co43aring Criteria with
S'(s'43tion
&ust be true for &ust be true for every set every set of test ases of test ases
Example Example E If a test set has overed every E If a test set has overed every
bra"h i" a program /satisfied the bra"h bra"h i" a program /satisfied the bra"h
riterio"0, the test set is guara"teed to riterio"0, the test set is guara"teed to
also have overed every stateme"t also have overed every stateme"t
May 8, 2014 CSIT5100 4/
Test Coverage Criteria
+ormal overage riteria are used to deide +ormal overage riteria are used to deide
whih test i"puts whih test i"puts to use to use
&ore likely that the tester will &ore likely that the tester will fi"d fi"d
problems problems
Breater assura"e that the software is of Breater assura"e that the software is of
high !uality high !uality a"d a"d reliability reliability
2 goal or 2 goal or stoppi"g rule stoppi"g rule for testi"g for testi"g
Griteria makes testi"g more Griteria makes testi"g more effiie"t effiie"t a"d a"d
effetive effetive
1ut "ow do we start to a22ly t"ese ideas in 2ractice
1ut "ow do we start to a22ly t"ese ideas in 2ractice
May 8, 2014 CSIT5100 48
S'44ary
Testi"g is
Testi"g is
"o
"o
lo"ger
lo"ger
a" :art form;
a" :art form;
$2<;7
$=>=<;7
("is gra2" may re2resent
statements @ )ranc"es
met"ods @ calls
com2onents @ signals
$2<;7
$=>=<7
%at"
Cover every path
$2<;7
$2<7
$=<;7
$=<7
$=>=<;7
$=>=<7 9
x # =-
x # 0-
y # H I x-
May 8, 2014 CSIT5100 51
Bn-assesse) Ho4ewor<
'hih 'hih riteria riteria work best o" e"terprise, highly work best o" e"terprise, highly
reliable softwareD reliable softwareD
,ow a" we best ,ow a" we best automate automate this testi"g with robust this testi"g with robust
toolsD toolsD
#esign structure
Use cases
A set N
0
of initial nodes) N
0
is not empty
A set N
f
of final nodes) N
f
is not empty
* n
i
) n
j
+) i is predecessor) j is successor
May 8, 2014 CSIT5100 5
Three "#a$p%e Graphs
0
2 1
3
N
0
= { 0 }
N
f
= { 3 }
0
2 1
3
N
0
= { }
N
f
= { 3 }
9
0
4 3
7
1
5
8
2
6
N
0
= { 0, 1, 2 }
N
f
= { 7, 8, 9 }
Not a Not a
valid valid
graph graph
May 8, 2014 CSIT5100 &
'aths in Graphs
Single9entry) single9e8it
A graph with only one node will not ha'e any edges
>t may be boring) but formally) 4dge Co'erage needs to re-uire :ode Co'erage on this graph
<e ha'e the same issue with graphs that only ha'e one edge . for 4dge Pair Co'erage 2
0
1
0
May 8, 2014 CSIT5100 15
15
Covering M+%tip%e ")ges
:o internal loops
def *n+ or def *e+ , The set of 'ariables that are defined by node n
or edge e
use *n+ or use *e+ , The set of 'ariables that are used by node n
or edge e
&oal5 /r0 to ",s(r" that val("s ar" #o+p(t"d a,d (s"d #orr"#tl0
0
2
1
6 3
5
4
B = 42
C = B*8
C = B?2
'"fs5 d"f $0% = {B}
d"f $4% = {C}
d"f $5% = {C}
Ds"s5 (s" $4% = {B}
(s" $5% = {B}
May 8, 2014 CSIT5100 25
4 'airs an) 4 'aths
du *n
i
) n
j
) v+ . the set of du9paths from n
i
to n
j
du *n
i
) v+ . the set of du9paths that start at n
i
Three criteria
/h", 1" +aE" s(r" that "v"r0 d"f r"a#h"s all possi)l" (s"s
-i,all0, 1" #ov"r all th" paths )"t1"", d"fs a,d (s"s
branch predicates
defs
uses
May 8, 01! CSIT5100 !
C%G & The if State'ent
if (x < y)
{
y = 0;
x = x + 1;
}
else
{
x = y;
}
4
1
2 3
x >= y x < y
x = y
y = 0
x = x + 1
if (x < y)
{
y = 0;
x = x + 1;
}
3
1
2
x >= y
x < y
y = 0
x = x + 1
4
1
2 3
x >= y x < y
x = y
y = 0
x = x + 1
May 8, 01! CSIT5100 5
C%G & The if-(eturn State'ent
if (x < y)
{
return;
}
print (x);
return;
3
1
2
x >= y
x < y
return
print (x)
return
NO edge from node 2 to 3.
The return node mut !e ditin"t.
May 8, 01! CSIT5100 )
*oops
) is an input to a program
"esearch
Pri#ate non$commercial
Commercial
Advanced techniques
Generators
Very powerful
Often code-based
Usually incomplete
General purpose
Moderate techniques
Acceptors
Mostly complete
Some code-based
Often special purpose
Test manaement
Simple coverae
Metrics
!ode independent
May 8, 01! CSIT5100 "
Types of Test Tools
Co#erage analy%ers
&Acceptors'
,etrics
-nstrumentation support
Unit/ HttpUnit/ 0
Capture 1 replay
3ata flow
5ogic based
+unctional
,utation
"andom
>ode = or statement =
?. Create an array inde.ed by id =s 4 nodeCo#er @ A
B. -nsert an instrument at each node
nodeCo#er @ i A CCD
E. Sa#e nodeCo#er @ A after each e.ecution
Source code
;.ecutable
Present tables )
Aho are the users of the systems2 and what are they
trying to doD
Hisual +odeling with :ational :ose and U+'2 T. Iuatrani2 *ddison Aesley2 $445
connectors
&d'an%ed 1$tati$n
CSIT5100 16 scc
&%ti'ity*$23e%t 4.$w
+e.ati$nshi-s
Pay
Re"uest
service
#ake
order
Deliver
order
Collect
order
ill
order
Customer Sales Stockroom
ter$ination
CSIT5100 11 scc
&%ti'ity*$23e%t 4.$w
+e.ati$nshi-s
Pay
Re"uest
service
#ake
order
Deliver
order
Collect
order
ill
order
Customer Sales Stockroom
Order
[placed]
Order
[entered]
Order
[filled]
Order
[delivered]
CSIT5100 17 scc
4.$w Terinati$n
a&ort action
CSIT5100 20 scc
Tie ('ent
CSIT5100 21 scc
()%e-ti$n 5and.ing
exce#tion
hand!ers
CSIT5100 22 scc
Interr"-ts
CSIT5100 2- scc
When T$ Use &%ti'ity Diagras
8
in situations 'here a!! or $ost of the events re#resent the
co$#!etion of interna!!y"generated activities
procedural flow of control
8
to $ode! #ara!!e! &ehavior
9
'or4f!o's
9
$u!ti"threaded #rogra$s
8
genera!!y used in the ear!y stages of design
each activity must #e expanded as one or more
operations assigned to a specific class
+e,"ireent Ca-t"ring
S.C. Cheung
CSIT5100 25 scc
UML Views and Diagras
Structura! .yna$ic
Static
view
Use case
view
I$#!e$entation
vie'
.e#!oy$ent
vie'
State machine
view
ctivity
vie'
Interaction
view
C!ass
diagra$
Use case
diagra$
Co$#onent
diagra$
.e#!oy$ent
diagra$
O&+ect
diagra$
Statechart
diagra$
Se/uence
diagra$
Co!!a&oration
diagra$
ctivity
diagra$
CSIT5100 20 scc
Use Case M$de.
=ur#ose
ctors
=re"conditions
>!o' of ?vents
9 interactions &et'een actors and the syste$
9 &usiness !ogic
=ost"conditions
CSIT5100 -- scc
#ay In'$i%e Use Case
Purpose: !llo" #uyers to pay outstanding invoice&s(
Actors: Buyer' !ccounting )ystem
Preconditions: %he #uyer has received the goods or services ordered and
at least one invoice from the system$ %he #uyer no" plans to schedule the
invoice&s( for payment$
Flow of Events
0$ %he #uyer invokes the use case #y #eginning to #ro"se the invoices
received #y the system$ %he system checks that the content of each
invoice is consistent "ith the order confirmations received earlier$
1$ %he #uyer decides to schedule an invoice for payment #y the #ank' and
the system generates a payment re2uest to transfer money to the seller3s
account$ ! #uyer may not schedule the same invoice for payment t"ice$
4$ Later' if there is enough money in the #uyer3s account' a payment
transaction from the #uyer3s account to the seller3s account$ %he #uyer
and seller are notified of the result of the transaction$ %he #ank collected
a fee for the transaction' "hich is "ithdra"n from the #uyer3s account$
5$ %he use case instance terminates$
CSIT5100 -5 scc
#ay In'$i%e Use Case 8C$nt9d:
CSIT5100 -5 scc
Che%;.ist
In so$e situations3 infor$a! re/uire$ents of a syste$ are
avai!a&!e textua!!y3 e.g.3 re"engineering of an existing syste$
9
Have a!! the re/uire$ents &een a!!ocated to a use
case@
9
Has the sa$e re/uire$ent &een a!!ocated to
$u!ti#!e use cases@
9
re there use cases not referenced &y infor$a!
re/uire$ents
CSIT5100 -0 scc
4"rther &%ti'ities
Inc!udes Binc!udesC
9
ex#!icit!y incor#orates the &ehavior of another
use case
9
exa$#!es;
?xtend
9
extends a $ore genera! use case &y adding
s#ecific actions
9
extension #oint and condition
9
?xa$#!es;
na!ysis
9
(ore #recise s#ecification of each use case
rtifacts
9
C!ass diagra$
9 Interaction diagra$s
9 ctivity diagra$s
9
S#ecia! re/uire$ents < exce#tions
9
na!ysis #ac4ages
.o$ain $ode!
9
4ey &usiness o&+ects and their re!ations
:uyer UI
9
"F chec4 ne' invoices
9
G" inconsistent invoices
9
"F #ay invoice
9
"F fi!! in #ay$ent detai!s
9
G" #ay$ent reference < confir$ation
9
"F /uery #ay$ent status
9
"F s#!it invoice
9
H
Buyer
CSIT5100 5- scc
#hysi%a. UI Design
8ile Check Invoice etrieval *ayment 9elp
Open Invoice
Close Invoice
:-it
;e"<
=elete$$$
)earch$$$
;e"<
Open<
>uery$$$
Contents
?sing 9elp
*rocedures
Commands
=ialog Bo-es
!#out $$$
CSIT5100 55 scc
#hysi%a. UI Design
Invoice ;ame@
8ile !n Invoice
Invoices =irectories
OA
Cancel
9elp
eference Information
CSIT5100 55 scc
#hysi%a. UI Design
Invoice ef@
Invoice etrieval :ngine
OA Cancel
=ate@
Aey"ords@
)eller@
CSIT5100 50 scc
UI #r$t$ty-e
rchitectura! centric
CSIT5100 50 scc
Iterati'e and In%reenta.
Incremental
Iterative
A #ypical Process
CSIT5100 51 scc
#"re Water6a.. De'e.$-ent
#r$%ess
&equirements
Analysis
esign
Coding
'esting
L
I
S
K
TI(?
=ro&!e$; .e!ays Lis4 Leduction
CSIT5100 52 scc
Iterati'e De'e.$-ent
&%%e.erates +is; +ed"%ti$n
L
I
S
K
Iterative
2aterfa!!
TI(?
CSIT5100 5- scc
Inception Elaboration Construction Transition
Uni=ed De'e.$-ent #r$%ess
* Li6e Cy%.e
Phases
Core $ork%lo&s
Requirements
Analysis
Design
Coding
Testing
iter(
)*
iter(
)+
, , , , ,
iter(
)n!*
iter(
)n
Iterations
maBor milestone
CSIT5100 55 scc
Use Case Dri'en Iterati$ns
A message represents
a stimulus&
An interaction can e
reali'ed y invo(ing a
class met"od
)o"n *
+an( Operators
* Account Service
Re"3ew7''o#nt(3ame8999)
* Saving Accounts
Create Read! and Contin#e
De5osit C)e"#e
De5osit
CSIT5100 , scc
Intera'tion Diagrams
s"ows all t"e messages t"at an o!ect can send and receive
descries all t"e possile states an o!ect can get into during its
li%e time
6otation
inter%aces
SpellEc"ec(
Synonyms
Dictionary
reali'ation
U4@ 1&D notation
CSIT5100 02 scc
Com5onent Diagram
Testers can "eep adding tests until all mutants ha)e been
"illed
(nfection " A B
-eak
selective
Eliminate
ineffective
$!s
Generate
test cases
%un
e'uivalence
detector
$hreshold
reached
B
Cefine
coverage
threshold
no
) ($)
correct
B
'es
#i&
)
no
May 8, 2014 CSIT5100 12
'/y Mutation 'or(s
1ode co)erage
0dge co)erage
Clause co)erage
!"er"iew
!b#ect$!riented %aults
&'ample
inheritance
polymorphism
constructors
"isibility
X::n () uses v
X::n() uses v
2or an object of type Y, a data flow
inconsistency of v may e$ist and result in a
fault if m() is called, then n()
void f(7 o !
o'm((
o'n((
"
May 8, 2014 CSIT5100 1,
*n+%al+us C+nstructi+n 5ea6i+r
!*C51"
Random testing
Symbolic testing
Concolic testing
Random Testing
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
try 1: x = 0, y = 0;
try 2: x = 0, y = 1
...
try n: x = 1, y = 0
Random inut data
generation
Random user intera!tion
se"uen!e
Random data sele!tion from
database
#ombinations of all abo$e
Random Testing
Random testing
Symbolic testing
Concolic testing
Symbolic Testing $a.%.a. Symbolic
&'ecution(
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
Symbolic Testing $a.%.a. Symbolic
&'ecution(
foo (int x, int y) {
if (x>y) {
x = x + y;
y = x - y;
x = x - y;
if (x - y > 0) {
assert (false); // bug
}
}
}
Constraints*
a4b 55 b1a4-
[ a < = b ] E N D
[ a > b , b - a < = 0 ] E N D [ a > b , b - a > 0 ] f a i l
[ a > b ] b - a > ? 0
[ a > b ] x = ( a + b ) - a = b
[ a > b ] y = ( a + b ) - b = a
[ a > b ] x = a + b
a < ? b
x = a , y = b
6sing a %inear Constraint Sol+er
a4b 55 b1a4-
&7cient linear constraint sol+ers are a+ailable
Constraint Sol+ing wit/ 8/at1if
Analysis
b1a4-
a , -. b , 1
Automatic Software Testing
Random testing
Symbolic testing
Concolic testing
)ous/i% Sen
&sso!iate 'rofessor, (# )er*eley
Resear!+ &reas
"rogramming Systems. Software &ngineering.
"rogramming 9anguages. and :ormal Met/ods*
Software Testing. ;erifcation. Model C/ec%ing.
Runtime Monitoring. "erformance &+aluation. and
Computational 9ogic
Security
Concolic , Concrete < Symbolic
inputs of ' and y=
A concrete
e'ecution
in+ol+e e'ternal
or non1linear
function calls
So,e observation
)
See,s on%. one instance o* the new
s.ste, object is needed
)
Its ,ethods ,a. need to be ca%%ed *ro,
vario1s p%aces in the code
CSIT!"" 2L scc
Thir, Design #ssue
C%ass diagra,
77inter*ace88
Sa%e&ricingStrateg.
getTota%'Sa%e( : -one.
&ercent3isco1nt
&ricingStrateg.
percentage : *%oat
getTota%'s: Sa%e( : -one.
0bso%1te3isco1ntOverThresho%d
&ricingStrateg.
disco1nt : -one.
thresho%d : -one.
getTota%'s: Sa%e( : -one.
@@@
&ricingStrateg.
K
getTota%'s: Sa%e( : -one.
CSIT!"" 3 scc
Fourth Design #ssue -Ans.er/
SeB1ence diagra,
pdt := get&re3isco1ntTota%' (
s : Sa%e
t := getTota%' (
< : st := getS1btota%' (
t := getTota%' s (
:Sa%eLineIte,
:&ercent3isco1nt
&ricingStrateg.
Sa%e&ricingStrateg.
CSIT!"" 36 scc
Fifth Design #ssue
Is a senior
&1rchases on -onda.
http:HHhi%%side:netHpatternsH
http:HHc2:co,HpprH
http:HHso1rce,aking:co,HdesignRpatterns
http:HHwww:javaca,p:orgHdesign&atternH
Architecture Meeting Challenges
Via Discipline
CSIT5100
CSIT5100
S.C. Cheung
May 2014
CSIT5100 2 S.C. Cheung
Software Architecture
Architectural
Centric
Scalability
Reliability
Maintainability
Extensibility
Sot!are "uality Issues
Sot!are #rocess
CSIT5100 $ S.C. Cheung
Architectural Centric
Architectural
Centric
Scalability
Reliability
Maintainability
Extensibility
"uality issues arise% because
o co&'lexity
CSIT5100 4 S.C. Cheung
Trends in Software Technology
Manage Cople!ity
Manage Cople!ity
"ia "ia
Additional Discipline
Additional Discipline
Discipline in requirement modeling
Discipline in design
Discipline in programming
Discipline in testing
Discipline in requirement modeling
Discipline in design
Discipline in programming
Discipline in testing
Architecture
CSIT5100 ( S.C. Cheung
#ntity $ife%Cycles
Exa&'le
Creation
/ An entity >ust create% !ill be 'lace% in an un,eriie% state. The na&e o the
creator an% a ti&e*sta&' !ill be hel% as 'art o the create re?uest.
9'%ate
/ @hen an u'%ate re?uest is &a%e against an un,eriie% entity8 the u'%ate
re?uest is a%%e% an% &arAe%. A%%itional u'%ate can be entere%.
Cancellation
/ The latest change re?uest can be cancelle% by the originator8 'ro,i%ing no
a%%itional re?uests ha,e been entere% against it an% it has not been ,eriie%
or re>ecte% in the &eanti&e.
.eriication
/ Acce't or re>ect on the latest ,ersion o the entity.
CSIT5100 5 S.C. Cheung
#ntity $ife%Cycle for &unning
'istory #ntities
,eriie%
u'%ateRe?uest
createRe?uest
,eriie%
u'%ateRe?uest
createRe?uest
create
u'%ate un%o
,eriy
u'%ate un%o
un%o re>ect
re>ect
non*existent
non*existent
,eriy
CSIT5100 10 S.C. Cheung
Modi(a)le #ntities
2elete Re?uests %o not a''ly to Entities that ha% not been ,eriie% at
least once beore.
Exa&'les8
/ #ublic 0oli%ay Entities
/ Associations bet!een Currencies*#olitical Entities8 0oli%ays*#olitical
Entities8 an% #olitical Entities*#olitical Entities.
CSIT5100 1$ S.C. Cheung
$ife%Cycle for Modi(a)le *
Deleta)le #ntities
createRe?uest
,eriie%
u'%ateRe?uest
u'%ateRe?uestAter.eriie%
%eleteRe?uest
%elete.eriie%
un%o
create
un%o re>ect
,eriy
u'%ate
,eriy
re>ect
un%o
u'%ate
u'%ate un%o
re>ect
u'%ate un%o
,eriy
re&o,e
un%o
re>ect
non*existent
non*existent
,eriy
CSIT5100 14 S.C. Cheung
ti&eSta&' B int
state B int
get)CManager+-
set)CManager+-
getTi&eSta&'+-
incrTi&eSta&'+-
setState+-
getState+-
is2irty+-
2ataIte&
create+-
u'%ate+-
re&o,e+-
cancel+-
re>ect+-
,eriy+-
)CMgrIc
CCInterace77
i% B String
create+-
store+-
loa%+-
re&o,e+-
setI2+-
getI2+-
#ersistenceEntity
ac?uire+-
release+-
#oolMgr
o'en+-
close+-
begin+-
co&&it+-
abort+-
execute"uery+-
execute9'%ate+-
Connection
isIn+-
getIte&+-
a%%Ite&+-
re&o,eIte&+-
2ataCollection
o'en+-
close+-
ac?uire+-
release+-
#oolIc
CCInterace77
)CMgr
occu'ie%
1
D
1
D
a,ailable
1
D
i&'le&ent
1
i&'le&ent
2ataIte&
)CMgrIc
#ersistenceEntity
#oolMgr
Connection
2ataCollection
ti&eSta&' B int
state B int
get)CManager+-
set)CManager+-
getTi&eSta&'+-
incrTi&eSta&'+-
setState+-
getState+-
is2irty+-
i% B String
create+-
store+-
loa%+-
re&o,e+-
setI2+-
getI2+-
ac?uire+-
release+-
o'en+-
close+-
begin+-
co&&it+-
abort+-
execute"uery+-
execute9'%ate+-
isIn+-
getIte&+-
a%%Ite&+-
re&o,eIte&+-
create+-
u'%ate+-
re&o,e+-
cancel+-
re>ect+-
,eriy+-
o'en+-
close+-
ac?uire+-
release+-
#oolIc
)CMgr
CSIT5100 15 S.C. Cheung
2ataIte&
rate B int
%ate B int
setRate+-
getRate+-
set2ate+-
get2ate+-
Interest
CSIT5100 1( S.C. Cheung
Iportance of Software
Architecture
As a coherent solution
/ #ositi,e eects on %e,elo'er &orale an% 'ro%ucti,ity