Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)

  • View
    212

  • Download
    0

Embed Size (px)

Text of Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)

  • 8/19/2019 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 Netbeans 6.16.1Kiki Ahmadi  JUG-Bnek

  • 8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)

    2/16

    !hat is Unit Testing!hat is Unit Testing

    "ethd # testing that ve$i%es the individ&al &nits # the 'de is w$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)

    3/16

  • 8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)

    4/16

    Unit Testing in JavaUnit Testing in Java

    / mst &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)

    5/16

    !hat is J&nit!hat is J&nit

    s a &nit test #$amew$k in 0ava 2evelped b( Kent Be'k and 3$i'h

    Gamma

    !idel( &sed and 'mmnl( be'me standa$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)

    6/16

    Simple JUnitSimple JUnit

    $eate test 'lass and test 'ase. Use an asse$t methd #$

    ens&$ing methd &tp&t

    ◦ asse$t37&als)*

    ◦ asse$tT$&e)*

    ◦ asse$tNtN&ll)*

    an be invked man&all( b( $&nning the test 'lass $ a&tmated b( &sing ant s'$ipt

  • 8/19/2019 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& dn9t need t lad the 0a$ int netbeans p$0e't.

    B( de#a&lt the 0a$ is embedded in

    test liba$a$( #lde$ And als netbeans has test 'lass

    and test 'ase 'de gene$atin

    men&

  • 8/19/2019 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 0ava p$0e't.

    "ake a simple 'lass having bth $et&$n val&ed and vid methd.

    :et the $et&$n val&ed methd d simple p$'ess #$ eample additin $ s&bst$a'tin.

     J&st p$int smething in the vid methd.

  • 8/19/2019 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)

    10/16

    $eate Unit Test$eate Unit Test

    hse this men& in netbeans ◦ Tls ; $eate J&nit Test

     'hse s&itable ptins.

  • 8/19/2019 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)

    12/16

    Unit Test !indwUnit Test !indw

  • 8/19/2019 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)

    14/16

    Unit TestingUnit Testing

    Assign the va$iable val&e #$ the test 'ase.

    ?emve the #ail)* methd in

    $et&$n val&ed methd test. ?&n the test 'lass &sing Shi#t =

    @6.

    See the test $es&lt

  • 8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)

    15/16

     Test ?es&lt Test ?es&lt

  • 8/19/2019 Simple Java Unit Testing With Junit 4 1219807979820682 9 (1)

    16/16

     Thank 8& Thank 8&

    5ave a ni'e &nit testing da( #lks