0% found this document useful (0 votes)
15 views28 pages

Testng

8. TESTNG

Uploaded by

anky16gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views28 pages

Testng

8. TESTNG

Uploaded by

anky16gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

TESTNG

I
NTRODUCTI
ON:

I
tisanopensour
ceaut
omatedtest
ingf
ramewor
k;wher
eNGof
Test
NGmeansNextGener
ati
on.

 TestNGissi
milartoJUni
tbutiti
smuchmor
epower
ful
thanJUni
t
butsti
l
lit
’si
nspir
edbyJUnit.

I
tisdesignedtobebet
tert
hanJUni
t,especi
all
ywhent
est
ing
i
ntegr
atedclasses.

ADVANTAGESOFTESTNG:

I
tgi
vest
heabi
l
ityt
opr
oduceHTMLRepor
tsofexecut
ion

 Annot
ati
onsmadet
est
ersl
i
feeasy

 TestcasescanbeGr
ouped&Pr
ior
it
izedmor
eeasi
l
y

 Par
all
elexecut
ioni
spossi
ble

 Gener
atesLogs

 Dat
aPar
amet
eri
zat
ioni
spossi
ble

 Aut
omat
ical
l
yret
urnt
hef
ail
uret
estcase
STEPS:

 Downl
oadt
het
est
ngj
ar

 Addt
het
est
ngj
ari
ntheecl
i
psebui
l
dpat
h

 Addt
het
est
ngpl
ugi
ninecl
i
psemar
ket
place

Got
oecl
i
psemar
ket
placeandi
nst
all
test
ng


Addt
het
est
ngj
arf
il
eandconf
igur
e

Wehav
etocl
i
ckr
unast
est
ngt
est
Annot
ati
onsi
nTest
NG:

@BeforeSui
te:
Theannot
atedmet
hodwi
l
lber
unbef
oreal
ltest
sint
his
sui
tehaverun.

@AfterSui
te:
Theannot
atedmet
hodwi
l
lber
unaf
teral
ltest
sint
hissui
te
hav
er un.

@Befor
eTest
:Theannotatedmethodwi
llber
unbef
oreanyt
estmet
hod
bel
ongi
ngtothecl
assesinsidet
hetagi
srun.

@After
Test
:Theannotat
edmethodwil
lberunaf
teral
lthet
estmet
hods
bel
ongi
ngtothecl
assesinsi
dethet
aghaverun.

@Bef
oreGroups:Thel
istofgr
oupst hatt
hisconfi
gurat
ionmethodwil
l
r
unbefor
e.Thismethodisguaranteedtorunshort
lybefor
ethefi
rstt
est
met
hodthatbelongst
oanyoft hesegroupsisinv
oked.

@Af t
erGroups:Thel
istofgroupsthatthi
sconfigurat
ionmethodwil
lrun
after
.Thi
smet hodisguaranteedtorunshortl
yafterthel
asttestmet
hod
thatbel
ongst oanyofthesegroupsisinvoked.

@Bef
oreCl
ass:Theannot
atedmethodwil
lber
unbef
oret
hef
ir
stt
est
met
hodinthecurr
entcl
assisi
nvoked.

@Af
ter
Class:Theannot
atedmethodwi
l
lberunaf
teral
lthet
est
met
hodsinthecurr
entcl
asshav
ebeenrun.

@Bef
oreMet
hod:
Theannot
atedmet
hodwi
l
lber
unbef
oreeacht
est
met
hod.

@Af
ter
Met
hod:
Theannot
atedmet
hodwi
l
lber
unaf
tereacht
estmet
hod.

@Test
:Theannot
atedmet
hodi
sapar
tofat
estcase.
Or
der
edi
nwhi
cht
heannot
ati
onexecut
e:

Pr
ogr
am

Out
put
PRI
ORI
TY

 Wecanpasspr
ior
it
ytot
hepar
ti
cul
art
estcase.

 Wecanpassbot
hposi
ti
veandnegat
ivev
alue.

I
twi
l
lexecut
ebasedonascendi
ngor
der
.

IfwegiveSamepri
ori
tyt
heni
twi
l
lexecut
ebasedont
he
alphabet
icor
der
.
Ouput
:
Sui
te-
Col
l
ect
ionoft
estcases

Test
CasesCol
l
ect
ionofst
eps

Wecanal
soconv
ertt
oxml
byj
ustr
ightcl
i
ckt
hecl
assandgi
ve

Test
ngConv
ertt
oTest
ng
I
twi
l
lcr
eat
eaxml
for
m

I
NVOCATI
ON COUNT:

I
fyouwantt
orunt
hepar
ti
culart
estcasetorunformany
t
imes,
Wecanuseonemethodcall
edinvocat
iontestcase.

I
twi
l
lrunt
het
estcasef
ort
hatpar
ti
cul
art
imes

Pr
ogr
am:
Out
put
:
I
GNORI
NGTHETESTCASE:

 Fori
gnor
ingt
het
estcaseWecanuseonemet
hodcal
l
edEnabl
ed

 Whenweuseenabl
ed=f
alse,
I
twi
l
lski
pthepar
ti
cul
art
estcase

Out
put
:
PARAMETER:

Youwantt
opasst
hei
nputf
rom xml
sheetatt
hatt
imepar
amet
ersar
e
used

Youhav
etogi
ve@par
amet
erannot
ati
onont
het
estcase
Out
put
:

@Opt
ional

I
ncaseofpar
amet
eri
snotexact
lymat
ched@opt
ionali
sused

Youhav
etopasst
hev
alueatt
het
imeofi
nit
ial
i
zat
ion:
Her
eIam wr
ongl
ypasst
hepar
amet
erandIpasst
heopt
ional
val
uet
o.

Out
put
:

Her
eitt
aket
hev
aluef
rom t
heopt
ional
notf
rom t
hepar
amet
er.
Par
all
elExecut
ion:

Thr
ead-
oneper
sonexecut
eal
lthef
unct
ioni
nthepr
ogr
am.

Mul
tiThr
ead-morethanoneper
sonwi
l
ltr
ytoexecut
eal
lthef
unct
ioni
n
t
heprogr
am paral
lel
.

Def
aul
tthr
eadcounti
s5.

I
fyouwantt
oexecut
ethe10t
estcasey
ouhav
etosett
het
estcaseas
10.

Mul
ti
posi
ngt
est
:

Runt
het
estcasesi
nmanybr
owseri
scal
l
edmul
ti
posi
ngt
est
.

Wecanseewhathappeni
fwedon’
tgi
vepar
all
elexecut
ion
Her
eal
lthe5t
est
swi
l
lber
unbyonl
yonet
est

Way
stopar
all
elexecut
ion:

 Test

 Met
hods

 Cl
asses
Cl
asses:
Out
put
:
Met
hods:
Out
put
:

Dependsonmet
hods
Out
put
:
I
ncaset
hedependedmet
hodi
sfal
sei
tski
pthemet
hod

Ouput
:

Her
ethet
est1i
sfai
lther
efor
etest
2isski
pped.
Gr
oups:

Wecangr
oupt
hemul
ti
plet
estcasesbyusi
nggr
oupsconcept

Wehav
etogi
vegr
oupsnamei
nthe@t
estannot
ati
on

@Test
(gr
oups=”
grpname”
)
Out
put
:
Re-
execut
ethef
ail
edt
est

Whenweknowt heparti
cul
art
estcasei
sfai
l
ed.Wehav
etouse
Ret
ryAnal
yzeri
nter
facei
sused

Pr
ogr
am f
orr
etr
ycl
ass:
Pr
ogr
am:

Out
put
:

Her
emethod1isexecuted3ti
mesbecausei
nthatt
estIment
ion
r
etr
yanal
yzer
=Ret
ryFai
l
ed.cl
ass

Test2isalsofai
l
edbutIdon’
texecut
e4t
imesr
easoni
sIdon’
tment
ion
ret
ryanal
yzer
=Retry
Fai
l
ed.cl
ass
Re-
Execut
ethet
estcasewedon’
tknow:

Forr
e-execut
etheal
ltestcasewehav
etouseI
Annot
ati
onTr
ansf
ormer

Pr
ogr
am f
orI
Annot
ati
onTr
ansf
ormer
:
Pr
ogr
am:

Out
put
:

Her
eAl
lthef
ail
edt
estar
eex
ecut
ed3t
imes.

You might also like