3. LES 3 RÈGLES DU TDD
On n'ajoute du code que pour faire passer un test
Les tests doivent être le plus simple possible
On écrit le minimum de code requis pour faire passer le
test
6. AVANTAGES
Vérification permanente du bon fonctionnement du code
Documentation toujours à jour
Confiance dans son refacto
Moins de temps passé à débugger
Code mieux conçu
7. QUE VOULONS-NOUS ?
Exécution rapide !
Exécution dans un environnement réaliste
Simulation des évènements utilisateur
12. ON TESTE
ts(O pu aotru cnat,fnto( {
et"n et jue n otc" ucin)
vrve =nwApCnatVe(#otcs)
a iw
e p.otcsiw'cnat';
ve.dCnat'onDe)
iwadotc(Jh o';
o((#otcs)hm(.ac(Jh De);
k$'cnat'.tl)mth'on o')
};
)
20. MOCK ET XHR
AVEC MOCKJAX
$mcjx{
.oka(
ul 'sac'
r: /erh,
cnetye 'etjo'
otnTp: tx/sn,
rsosTm:70
epneie 5,
rsosTx:{rsls [.]}
epneet
eut: ..
};
)
21. MOCK ET XHR
AVEC SINON.JS
atrfnto ( {
fe(ucin )
jur.jxrsoe)
Qeyaa.etr(;
};
)
i(sol sac' fnto ( {
t'hud erh, ucin )
snnsu(Qey "jx)
io.tbjur, aa";
ApCnat.erh'onDe,snnsy);
p.otcssac(Jh o' io.p()
asr(Qeyaa.aldihac( ul 'oapcm })
setjur.jxcleWtMth{ r: mnp.o' );
};
)
22. SINON.JS
SPIES
i(sol cl sbcieso pbih,fnto ( {
t"hud al usrbr n uls" ucin )
vrclbc =snnsy)
a alak
io.p(;
Pbu.usrb(msae,clbc)
uSbsbcie"esg" alak;
Pbu.ulsSn(msae)
uSbpbihyc"esg";
asrTu(alakcle)
setreclbc.ald;
};
)
23. SINON.JS
STUBS
i(sol cl alsbcies ee i teeaeecpin" fnto( {
t"hud al l usrbr, vn f hr r xetos, ucin)
vrmsae='neapemsae;
a esg
a xml esg'
vrerr='neapeerrmsae;
a ro
a xml ro esg'
vrsu =snnsu(.hos)
a tb
io.tb)trw(;
vrsy =snnsy) sy =snnsy)
a p1
io.p(, p2
io.p(;
Pbu.usrb(esg,su)
uSbsbciemsae tb;
Pbu.usrb(esg,sy)
uSbsbciemsae p1;
Pbu.usrb(esg,sy)
uSbsbciemsae p2;
Pbu.ulsSn(esg)
uSbpbihycmsae;
asr(p1cle)
setsy.ald;
asr(p2cle)
setsy.ald;
asr(tbcleBfr(p1)
setsu.aldeoesy);
};
)
24. SINON.JS
MOCKS
i(sol cl alsbcieswe ecpin" fnto ( {
t"hud al l usrbr hn xetos, ucin )
vrmAI={mto:fnto ( { }
a yP
ehd ucin ) } ;
vrsy=snnsy)
a p
io.p(;
vrmc =snnmc(yP)
a ok
io.okmAI;
mc.xet(mto".ne)trw(;
okepcs"ehd)oc(.hos)
Pbu.usrb(msae,mAImto)
uSbsbcie"esg" yP.ehd;
Pbu.usrb(msae,sy;
uSbsbcie"esg" p)
Pbu.ulsSn(msae,udfnd;
uSbpbihyc"esg" neie)
mc.eiy)
okvrf(;
asr(p.aldne;
setsycleOc)
};
)
28. UI TESTING
DECLENCHER DES EVENTS D'UI
fnto smltCikslco){
ucin iuaelc(eetr
ty{
r
vreet=dcmn.raevn(Muevn";
a vn
ouetcetEet"osEet)
eetiiEet'lc' tu,tu)
vn.ntvn(cik, re re;
dcmn.urSlco(eetr.ipthvn(vn)
ouetqeyeetrslco)dsacEeteet;
}cth(){
ac e
trwnwErr'atciko eeet '+slco,e;
ho e ro(Cn' lc n lmn:
eetr )
}
}
29. UI TESTING
DECLENCHER DES EVENTS D'UI #2
fnto smltCikslco){
ucin iuaelc(eetr
ty{
r
vreet=nwMuevn(cik,{
a vn
e osEet'lc'
'iw:wno,
ve' idw
'ube' tu,
bbls: re
'aclbe:tu
cneal' re
};
)
dcmn.urSlco(eetr.ipthvn(vn)
ouetqeyeetrslco)dsacEeteet;
}cth(){
ac e
trwnwErr'atciko eeet '+slco,e;
ho e ro(Cn' lc n lmn:
eetr )
}
}
30. UI TESTING
DECLENCHER DES EVENTS D'UI #3
fnto smltKycinslco,ato,crmCd,fCd,siteAg {
ucin iuaeeAto(eetr cin hoeoe foe hfKyr)
ty{
r
vreet=dcmn.raevn(KyorEet)
a vn
ouetcetEet"ebadvn";
i (vn.ntebadvn){ / Crm,I
f eetiiKyorEet
/ hoe E
eetiiKyorEetato,tu,tu,dcmn.ealVe,
vn.ntebadvn(cin re re ouetdfutiw
crmCd,0 ",fle ")
hoeoe , " as, ";
}es {/ F
le
/ F
eetiiKyvn(cin tu,tu,dcmn.ealVe,fle
vn.nteEetato, re re ouetdfutiw as,
fle siteAg fle fCd,0;
as, hfKyr, as, foe )
}
dcmn.urSlco(eetr.ipthvn(vn)
ouetqeyeetrslco)dsacEeteet;
}cth(){
ac e
trwnwErr'at'+ato +'o eeet '+slco,e;
ho e ro(Cn'
cin
n lmn:
eetr )
}
}
32. KARMA
rpalege~Cd/yaj$krasatsrhcn.s
ahe@al:/oesrhs am tr ya.ofj
IF [am] Krasre satda ht:/oahs:86
NO kra: am evr tre t tp/lclot97/
IF [anhr:Satn bosrFrfx
NO luce] trig rwe ieo
IF [anhr:Satn bosrCrm
NO luce] trig rwe hoe
IF [hoe2. (iu):Cnetdo sce i Oed0LsVk_4
NO Crm 40 Lnx] once n okt d 680_-oDxeG
IF [ieo 1. (iu):Cnetdo sce i jBg4VI8B_4
NO Frfx 90 Lnx] once n okt d mn2HrCxXeH
Crm 2. (iu) Eeue 5 o 5 SCES(.8 sc /296sc)
hoe 40 Lnx: xctd 8 f 8 UCS 319 es
.8 es
Frfx1. (iu) Eeue 5 o 5 SCES(.8 sc /309sc)
ieo 90 Lnx: xctd 8 f 8 UCS 328 es
.3 es
TTL 16SCES
OA: 1 UCS
33. SI VOUS UTILISEZ UN
FRAMEWORK
Ne testez pas votre framework !
Unit-testez vos propres libs
Unit-testez l'intégration avec des libs "3rd-party"
Ecrivez des tests d'intégration
36. PAGE/ZONE OBJECTS
Expose les "services" rendus par une page/zone
Encapsule la structure HTML
Ne doivent pas porter la responsabilité des assertions