simple java unit testing with junit 4 1219807979820682 9 (1)
TRANSCRIPT
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 1/16
Simple Java Unit TestingSimple Java Unit Testing
with JUnit 4 and Netbeanswith JUnit 4 and Netbeans6.16.1Kiki Ahmadi
JUG-Bnek
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 2/16
!hat is Unit Testing!hat is Unit Testing
"ethd # testing that ve$i%esthe individ&al &nits # the 'de isw$king p$pe$l( )!ikipedia*.
Test the smallest &nit in s&$'e'de
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 3/16
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 4/16
Unit Testing in JavaUnit Testing in Java
/ mst &sed testing #$amew$k in 0ava
◦ J&nit
◦ TestNG This time we &sed J&nit be'a&se
its embedded in netbeans 6.1.
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 5/16
!hat is J&nit!hat is J&nit
s a &nit test #$amew$k in 0ava2evelped b( Kent Be'k and 3$i'h
Gamma
!idel( &sed and 'mmnl( be'mestanda$d &nit test #$amew$k
s pa$t # Unit #amil(. Unit is a
p$ted J&nit #$ va$i&s lang&age.◦ 5&nit )5*
◦ N&nit).N3T*
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 6/16
Simple JUnitSimple JUnit
$eate test 'lass and test 'ase.Use an asse$t methd #$
ens&$ing methd &tp&t
◦ asse$t37&als)*
◦ asse$tT$&e)*
◦ asse$tNtN&ll)*
an be invked man&all( b($&nning the test 'lass $a&tmated b( &sing ant s'$ipt
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 7/16
J&nit in Netbeans 6.1 J&nit in Netbeans 6.1
8& dn9t need t lad the 0a$int netbeans p$0e't.
B( de#a< the 0a$ is embedded in
test liba$a$( #lde$And als netbeans has test 'lass
and test 'ase 'de gene$atin
men&
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 8/16
:ets 2 The de:ets 2 The de
:ets sta$t with heating &p &$Netbeans 6.1 and '$eate new 0avap$0e't.
"ake a simple 'lass having bth$et&$n val&ed and vid methd.
:et the $et&$n val&ed methd dsimple p$'ess #$ eample additin$ s&bst$a'tin.
J&st p$int smething in the vidmethd.
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 9/16
Simple"ath.0avaSimple"ath.0ava
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 10/16
$eate Unit Test$eate Unit Test
hse this men& in netbeans◦ Tls ; $eate J&nit Test
<$ 0&st simpl( p$ess t$l = Shi#t = U.
A windw dialg&e will appea$>'hse s&itable ptins.
<$ (& 'an leave it as is. :ike
&s&all( d
. Test 'ase will a&tmati'all( b&ild
inside the test pa'kage #lde$.
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 11/16
Unit Test "en&Unit Test "en&
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 12/16
Unit Test !indwUnit Test !indw
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 13/16
Simple"athTest.0avaSimple"athTest.0ava
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 14/16
Unit TestingUnit Testing
Assign the va$iable val&e #$ thetest 'ase.
?emve the #ail)* methd in
$et&$n val&ed methd test.?&n the test 'lass &sing Shi#t =
@6.
See the test $es<
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 15/16
Test ?es< Test ?es<
8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)
http://slidepdf.com/reader/full/simple-java-unit-testing-with-junit-4-1219807979820682-9-1 16/16
Thank 8& Thank 8&
5ave a ni'e &nit testing da( #lks