/К - г../î m A Parameterized Unit Test Framework Based on Java PathFinder VU THANH NHAN Faculty of Information Technology University of Engineering and Technology Vietnam National Unive
Trang 1/К - г /
î m
A Parameterized Unit Test Framework
Based on Java PathFinder
VU THANH NHAN
Faculty of Information Technology University of Engineering and Technology Vietnam National University Jirtnoi
Trang 2Table of Contents
1 1 丁l i e m o t i v a t i o n 3
1 /2 O u r s o l i l i i o n 3
1 3 C o n t r i b u t i o n 5
1 4 T h e s i s s t i uc t u i e 5
2 A u t o m a t i c t e s t d a t a g e n e r a t i o n 7 2 1 T e s t a ( l ( 4 | t i a c y c r i t e r i a 8
2 1 1 D a t a - H o w o r i e n t e d a d e q u a c y c r i t e r i a 9
2 1 2 C o n t r o l - f l o w o r i e n t e d a d e q u a c y c r i t e r i u 1Ü 2 2 U n i t l e s t a n d P a r a m e t e r i z e d U n i t T e s t 11
2 2 1 U n i t T e s t 11
2 2 2 I V u c iM ie t e r iz e d U n i t T e s t 1 3 2 3 T e s t i n p u t g e n e r a t i o n b y s y m b o l i c e x e c u t i o n 15
2 3 1 S y m b o l i c e x e c u t i o n 1ช
2 3 2 C J o i i ť i a l i z e d s y m b o l i c e x e c u t i o n w i t h l a z y i n i t i a l i z a t i o n 2 0
2 3 3 C o d e i l i s t r u i n e n t a t i o n f o r s y m b o l i c e x e c u t i o n 2 2
3 ] T e s t D a t a G e n e r a t o i 2 6
3 2 A i c l i i t ( 4 * t i u e o f S y m b o l i c J a v a P a t h F i i i d i T 2 8
3 2 1 T h e I n s t r u c t i o n ドm t m y 2 9
3 2 2 A t t r i b u t e s f o r s t o r i n g s v n i b o l i c i n f o r m a t i o n 3 1
3 2 3 l i a ỉ ì d l i n g Ы а ш і і і п ц c o n d i t i o i j s w i t 11 C l i u i c c C ! ( sn e r a l ( > r s 3 2
3 2 1 Sc、w r a l e x a m p l e s o f s y m b o l i c e x t '( u t u )H i n S y m b o l i c 115 F . 3 5
Trang 3p U T F r a m e w o r k 4 21.1 1>1 *1 F r a m e w o r k o v e r v i e w 12
Trang 51
Trang 8l i s t o f t e s t c a s e s t h a t le a d t o e r r o r s o r f a i l u r e s
K i & i n e 1 1 : F i a i t i o w o r k o v e r v i e w
I lie r e s u l t i n g t r a i m n v o r k c a n ỊH o c e s s ĩ n a ỉ i v P L T s i i ) a m i l t i m e , h c c s Ị ) i o g i a _ n u i i r i s
Trang 128 C h a p te r 2 A u to m a tic test d a ta generation
o f buys, bat ïicva- th e ir ab^itîiœ. l l i b d a i m c a n b e u i u l e i s t o o d t h a t:t e s t i n g
Trang 132 Л Test adequacy criteria 9
Trang 1410 C ha p te r 2 A u to m a tic test d ata generation
111 t lu 、c o n t r o l - f i o w o r i e l it C'd a d e q u a c y c r i t e r i a a p p r o a c h , w e u s e a c o n c e p t o l c o n t r o l
H o w ц і а р і і ( C F ( Ỉ ) a s a a b s t r a c t H ? [ ) i e s c 'u t f it io n o f a p r o g m i i L F o m i a l l y a c o n t r o l
H o w g r a p h o f a p m g m m p , с F C ( P ) is a H n i t e e d g e - l a b e l , d i r e c t e d g r a p h G =
{ V J { ร , e } r L \ L ), w h e r e Л is t h e s e t o f n o d e s , E is t h e s e t o f e d g e s ( i e E = { ( " เท )\ỉt, m e N บ {.ร r } } ) L is t h e s e t o f l a b e l s o f e d g e s , ,ร is t h e e iiU y n o d e , e is
і н і г ф і а х у c r i t e r i a :
:
Trang 152.2 U n it Test and P aram eterized U n it Test 11
Trang 1612 C h a p te r 2 A u to m a tic test d a ta generation
piใы i с Í: 1 s s PUT test_add () (
|Mih»Ị.i« V« >id PlJT]_add (in t :ч, ііИ у) { ưnde rTest u t = I»“ w Under Te s t 0 ;
in t ш = Mat h.abs ix.) + Math abs (y) ;
a s s e rtT ru e ( u t Add(X, y) == m );}
Test class rruJi I]T s Tesi CÌ/ÍSS w iứt P V T
F i g l i l e ^ ; ! : E x a m p l e o f U T a n d P U T
l u t l æ a b o v e e x a m p l e I 'T J ť s t jiild is t e s t ch u s s a m i i t s m r t h o d s a r e l i n i t t e s t s o f
A d d ịin t ร i n t y).
Trang 18C h a p te r 2 A u to m a tic test d a ta generation
Trang 192.3 Test input, generation by sym bolic execution 15
r e a c h t o h i g h c o d e c o v e r a g e เท í ì d d i t i o n p и F s a m 1)(' u s ẹ d symbolic summaries
w h i c h c illo w .st/rnljolic tjx c a tio n l o s c a le f o r a i ' b i t i ' c i i y a b s t r a c t i o n l r v (、ls
T h e r e a n ' s e v e r a l d i f f e r e n t t e c l i n i ( i u e s Cor H i i t o m a t u d t e s t i n p u t : g i ü K H a t i o n , s u o li
<us r a n d o m t e s t ( l a t a g e n e r a t i o n ( J O f f u t t & H U iy e s , 1 9 9 6 ),g o a l - o r i e n t e d t e s t d a t a
g e n e r a t i o n ( K o r e l к A l - Y a n i i 1 9 9 6 ) | ) a t h - o i i ( ' i i t r 4 l t e s t d a t a g c n o i a t i o u ( K o r e l
1 9 9 0 ) H H 't h o d s e q u e n c e s a n d s t a t e e x p l o r a t i o n ( I h a i i t o l a 2 0 0 6 ) I l l t h i s s e c t i o n , w e
i n t i o d u c e symbolic execution - a to c lin iq u e is m o s t ly u se d fo r Ы g e iie r a t io ii arici i t s
s u p p o r t i n g t e d m i < |니ě s : lazy in itia liz a tio n a n d code in s tru m e n t
2.3.1 Sym bolic execution
Trang 2016 C h a p te r 2 A u to m a tic test d ata generation
Trang 212/Л. Test in p u t generation by sym bolic execution 17
ťa lii
The concrete execution pash
f ř c て IMI« I J
ịí*» tnu Ị :false
Trang 22T h i s t e c h n i q m * is I i s r d i n J a v a P a t l i K i n d e r f o r t e s t i n p u t g e n e r a t i o n
A n d i n t h e r e c e n t y e a r s , n u m e r o u s r e s e a r c h e s p r o p o s e a n e w i d e a o f s y m b o l i c
G o i i e i a l l v , ( l y n a i n i r s y m b u l i c e x c 4 :i i t i o u is t h ( j c o u i b i n a t i o n <>l ( 4 ) iK T e t e e x w ' u t i u i i a n d
s y n ih u lk : e x c n i t k m , t h is c o m b i n a t ІПМ a llo w s fo r t Ili.1 p r o g r a m t o b e exec u tt 'd in a n y
18 C h a p te r 2 A u to m a tic test d ata generation
Trang 24C hapter 2 A u to m a tic test data generation
Trang 252.3 Test in p u t generation by sym bolic execution 21
Trang 26\ \ lir n t lu 、exe e a tio n fW4 : f*sscs an im -in itìa liz (4Ỉ гНѴчѵшч1 field, the a lg o rith m
n o n (l( f( n n i u h d i c u l l Ị i in itia liz e s th e fie ld น ) \h v n u ll value, to a n ew o h jc r t
In model checker Opel at ion the program in stru m e nta tion (which translate source
(i( 、 c l a n 、 îy jx * > cl I a lilie s t o I lift (ft I Htịỉìí.s.sìoh O p é r a tio n s iii v o lv i li » t l lese v a ria b le s HK1
22 C hapter 2 A u to m a tic test data generation
Trang 27п і р і ж т ч і w i t h a p p r o p r i a t o 1И ( Ч І10(1 c a l l s t h a t m a n i p u l a t e ' o b j e c t s o f t y p e Jn U yrrlù:- prcs.sioỉỉ. Ч Ъ е t y p e a n a l y s i s c a n b e ( l o n e b y t o o l o f B a u d m i ( C o r b e t t e t a ] , 2 0 0 0 )
Trang 29T h e J V M o f I P K li a s ( a p a h i l i t v o f s t a t e s m a l i a요r m r n t : b a c k t r a c k i n g , s t a t e
ods in the context o f till* VM -Searcli collaboration:
• Lf.4Ỉ( iff IS: C o iic th a t m o n ito r s Н 1 НІ c o n tr o ls J p F р іо д іа ш e x e r i i t i o !ᄂ
• N a tiv e H ťc rs : счн|(> I lia i s h o u ld be e x e c iitc fl o u ts id e .IP K (e.g I / o u p m u tk m s ).
Trang 3026 C h a p te r 3, Test cases generation w ith J P F
Trang 32g i i s o n к K o i ť l , 1 9 9 6 ) , s iin u lr it c 'd a n n e a l i n g ( N T r a c e y & M a n d e r 1 9 9 8 ) 1 r u l e - b a s e d ( D ecisori Vi a l 1 9 9 1 ) ra n c lo tn te s t ( la t a g e n e r a tio n ( J O f f u t t Ắ: H a y e s , 1 9 9 6 ), g o a l-
g r m 、 r a t i( m ( K o r e L 1 9 9 0 ) l)c 、 ỊMj m liu g O ll th e c h o s e n a p p ro a c h e s , th e r e a re d iř f e i- (ฯแ w a y s t o f in d th e p a th (’( m il it im i In .s y m b o lic e x e c u tio n , th e P a t li c o n d it io n is
^СПюсо C 'o iistra iiit Solv(jr: lit t p : / /с.: Ь о с о s o iir c e f o r g ii n e t /
*1 八SolvťT С어is tra in t S o lvri : h t t p : / / w w w e s 山r a n d e is e d u / t i m / A p p l e t s / I A s o iv e r h t m l
С !VC3 C o n stra in t S olver: h t t p : / / พ w w c s Iiy u e d u / a e s y s / c v ç 3
28 C hap ter 3 Test cases generatk)n w ith J P F
Trang 333/2 A rchitecture of Sym bolic Java P a th F in d e r 29
T w o m a i n m e c h a n i s m s o f S y r n b o l i c J a v a P a t h F i n d n i\w: bytecode im tr ụ c tĩo ii
fa c to ry Ш К І attributes associated w i t h t h e p r o g r a m s t a t e T h (、fir s t , o n e a l l o w s r e
p l a c i n g Ol* e x te iK Ü n g t l u 1 S ta n d a rd , c o n c re te e x e c u tio n s e m a n tic s o f b y te c o d e w it h a
F i r s t , w e c o n s i d e r t h í ' Ịìis tru c ịio n Factory a r c h i t e c t u r t i i n I F F c o r e A s k n o w ,
Trang 3430 Chapter 3 Test cases geucration with J P F
analymi i l l a s t a n d a r d t( 、 st ( la ta g c n e r a t o i.
Trang 353.2 A rchitecture of Sym bolic Java PathFincler 31
Trang 3632 C hapter 3- Test cases generation w ith J P F
n o t r n ( | i i i r < 、s u c l i Я |)|)І'()Х i l l i c i t e U l in l y s i s, s i n c e t h e s y i r i l ) o l i r iiifo iiiia tio ii is St ( 11441 i n
o f t h e Proqi'diif (inahjzu' Ị) a r t i l l a S ta n d a r d t e s t d a t a g e n e r a t o r a m i a n d associ a trd (ittribuic.s is u s e d f o r s t o r i n g t h e a im ly s iu g d a t a N o w w e r ( ) n s id ( : 4 t o t h e S i、( ( ) n ( l p a r t
- t li( * J}(itli yeurmt.ur. I l l J P F , t h e r o l e o f p a t h g e n e i c i t o r is d o n o b y Cf I о Ỉ ( v C r 11 a Ị at o r
Trang 373.2 A rchitecture of Sym bolic Java P ath F in d e r 33
• S e le c tio n o t (la s s e s I (ๆ )Í41ร(ฯ lt i n g ((lo ìíiH ÌM SỊX4:ÌH< ) ln M iiis tic s a n d p a r a m e te r -
iz a tio n o f C lio ic e C ie iie ia to r in s ta n c e s s h o u ld be p o s s ib le at I im t iin e , i.e v ia
JP I* ร c o n H ^ n ia tio ii iiio c h a n is in
Trang 3834 C ha p te r 3 Test cases generation w ith J P F
ѴЧ ГІ f y ĩ Ị c tt t o o i o đ r ( I С - í I ᄂ e fa se I ✓
V e ะ ; i y î r t ; í 4 ) С я { о 1 2 3 4 ^ ?
v c - r i i y ç e t D o u b l c f i , 0 , 1 Ь) С - { 00} ? ?
poteniiaìỉy la-qe s eis ^ »Ih tots oí นก 이 e re s irg va ᄂ es
ЛС t mìe va ue sei Without i'eufrsi cs
C o n fig u r a b le Heuristic Choice Models CO아gtratJte с asses to
create Cho ceGenerator instances
T 1 Дe.g T h re s h 이ปี* heuriSbc
I n f i g l i l e 3 5 , w o h a v e a n e x a m p l e o f Choice G en era tors u s a g e T o i m p l e m e n t
(jid D o u b lv () m e t h o d o f V tn fif d a、s s J P F u s e s t h e c o n i b i u a t i o n o f Choice C rn tra to rs
c l a s s is Do a Idr 7 7/1 rsh 0 Id a Cĩnrator. it j u s t s p e r i i i r s a s y m b o l i c n a m e lu lo c it.y '
w l i k h I I >F uses t o lo o k u p a ll a s s o c ia ti* !I c la s s Iia n ic fr o m it s c o i i i i g i u a t i o i i ( la ta
Trang 393.2 A rchitecture of Sym bolic Java P ath F in d e r 35
G cficra tor ( n n s h m t u r s ѴІН J P K c o n l i g u r a t i o n d a t a : rci()< n (f.fin ť s h o ld — 1 3 2 5 0
In a n u t s lir ll ( 'h o ic f'G c îio ia to r s o f J P F a re c o n fig iiia b lt', th e y a re usod to ІШ - Ịíỉẹ iu e n t a p p lic a tio n specific' h e u ris tic s fo r * a o n -d e te rin in is ti(* (la ta a c q u is itio n а ік і
Trang 40C hapter 3 Test cases generation w ith J P F
Trang 41Lis-3.2 A rchitecture of Sym bolic Java F a th F in d e r 37
Trang 4238 C hap ter 3 Test cases generation w ith J P F
Trang 44a n d Starch L islviiv.r i n t e r f a c e s,S fjrnbolk'Listeiier is e x t e r u l e d f i o r i i F i opr 1 'tyL i s itu e r-
i l l a d d i t i o n P ro p n t ijL iste ỈÌV7 Adapt с Ỉ' is e x t e m l e c l t r o n i G ^n c ricP ro p rrt Ợ c la s s
ru n i l l c o n c re te c x e c a itio n m o d o w it h in J P P s s p e c ia liz e d J a v a v ir i lia i n m c h in e a n d
he
40 C h a p te r 3 Test cases generation w ith J P F
Trang 453.2 A rchitecture of Sym bolic Java P a th F iiid e r 41
e a c h |)layi> t h e r o le o f t h re e |) a r t s i u a S ta n d a r d te s t (la ta , g e n e r a to r : Instructian
Factofifiÿ Associated attributes a n d Choiv.t Gcnemtora. W e i n t r o d u c e Listeners a s
a m e c h a n i s m t o i m p l e m e n t J P F e x t e n s i o n s - r h e v a r e t h e b a s is o f o u r f r a m e w o r k ’ s
d e v e l o p m e n t a n d t l i e i i u s a g (* w i l l b e p r e s e n t e d i l l m o r e d e t a i l i n t i l t * n e x t c h a p t e r ,
w h i c h e x a m i n e s t h e Г і а и к ч ѵ о і к m a < k * o f t l i e ( o i n b i n a t i o n ( ) i Symbolic J P F a n d J U n it
t h a t c a n g e n e r a t e a n d (.» x e c u te u n i t t e s t s a u t o m a t i c a l l y
Trang 4612
Trang 474.1 P U T Frainew ork overview 43
Trang 494.2 M a in com ponents o f P U T Fram ew ork 45
Trang 50M e t h o d Ị I t »*s i M d h o c I ร T i î s t M e l h u c ỉ L o « ( ỉ e i g i n T p s t M t ' t h o f l ( t ť s l ( M a s s N i i u u ? ) ะ
in p u t paiarnetei s lo r JPK g(*neicites и I s in the th ird St(.ๆ).
I n th e s e c o n d s te p : P U T Iiu m irr i n i t i a t e s a s h a i r d t.cstsyntlicsizcr. A s i t s
Trang 514.2 M a in com ponents of P U T Fram ew ork
- S p e c i f y t h e i n s t n i c t i o n f a c t c u y is (ỊOV.na.sa.jpf.symbc.ร (Ịììibolichistructi(m h\ictory
( l i n e 6 )
- R e g i s t e r pul f iu m V w o t'k p ITTListtn(Si' <IS t h e l i s t e n e r ( l i n e 8 )
- G m iig v n e th e Sexuell o b j e c t w ith Ị)rũi Víiluc \ s ( (U f h j f i a l t i p l ť j r r o r s , t i u e }
p r i v a t e s t a t i c v o i d lUii.J PK ( S t r i n g i.osiCUysNatiu* , iMř»!lu>{:l test M eth od ) {
Trang 52F in a lly n a nv\K inst ance o f J F F is c r e a t e d wit 11 the ШПѴ CtmỷÌỊỊ object, and
r a u g h t น) p r i n t Stdik'Tracr w lje iie v e i a i l u u h a n d le d c x c r p t iu i i (K T 11 IS ( l i n i n g th e
c o l l e c t o r ( ) f P V T F ra iiiiw o rk I t is e x t e n d e d f r o i r i G t m lie Property d a s s ( l o c a t e d i n
- O v e r w r i t e s propal t y V iolatť.f) m e t h o d o f Search L is i t V с ไ * i n t e r f a c e f o r p r i n t i n g