+ All Categories
Home > Documents > Lect5 6a Test Debug

Lect5 6a Test Debug

Date post: 02-Jun-2018
Category:
Upload: phuongsky
View: 233 times
Download: 0 times
Share this document with a friend

of 80

Transcript
  • 8/10/2019 Lect5 6a Test Debug

    1/80

    Software Engineering

    2013

    Lecture 5 & 6:Unit testing & debugging

  • 8/10/2019 Lect5 6a Test Debug

    2/80

    2013 FIT330 Software Engineering 2

    Outline

    What is testing?

    Test (stand-alone) procedures:

    Blac bo! "s #hite bo! testing

    $e"elop and run tests using %Unit

    $eensi"e progra''ing

    $ebugging

  • 8/10/2019 Lect5 6a Test Debug

    3/80

    2013 FIT330 Software Engineering 3

    What is testing?

    or' o progra' "alidation alidation 'eans to "alidate our belie that a

    progra' unctions correctl*:

    i+e+ satisies its speciication in practice, #e can best increase our conidence

    Testing to use real data to test a progra' to'eet its speciication

    1

  • 8/10/2019 Lect5 6a Test Debug

    4/80

    2013 FIT330 Software Engineering 4

    Testing 'ethod

    Test incrementally

    Three techni.ues:

    unit testing:test each 'odule in isolation

    integration testing: test a group o 'odules regression testing: re-run tests ater 'odiications

    T#o basic steps:

    generate test cases de"elop & run tests

  • 8/10/2019 Lect5 6a Test Debug

    5/80

    2013 FIT330 Software Engineering 5

    Test case

    /!hausti"e testing is i'practical 0oal: ind a s'all, representati"e set o test

    cases

    Test case is a set o input data "alues o agi"en test unit

    Belie: succeeds #ith T1s 2 succeeds #ith allinput

  • 8/10/2019 Lect5 6a Test Debug

    6/80

    2013 FIT330 Software Engineering 6

    Test case

    int

    ?

    Test cases someMethod(int x, int[] a)

    int[]

    3nput do'ains

  • 8/10/2019 Lect5 6a Test Debug

    7/802013 FIT330 Software Engineering 7

    Test stand-alone procedures

    0enerate test cases: blac-bo! "s+ #hite-bo!

    $e"elop and run test:

    use %Unit

    2

  • 8/10/2019 Lect5 6a Test Debug

    8/802013 FIT330 Software Engineering 8

    0enerate test cases

    Ob4ecti"e: ind approximationso the inputdo'ains

    ppro!i'ation based on representati"e testdata sets (T$s)

    T#o basic steps:

    0enerate T$s

    1o'bine T$s to or' test cases

    2a

  • 8/10/2019 Lect5 6a Test Debug

    9/802013 FIT330 Software Engineering 9

    0enerate T$s

    intGenerate TDSs

    x1

    x2

    int[]

    a1

    a2

    a3

    a4

    a5

    someMethod(int x, int[] a)

    TDS

  • 8/10/2019 Lect5 6a Test Debug

    10/802013 FIT330 Software Engineering 10

    1o'bine T$s

    intGenerate TDSs

    Combine TDSs

    x1

    x2

    int[]

    a1

    a2

    a3

    a4

    a5

    ...

    someMethod(int x, int[] a)

  • 8/10/2019 Lect5 6a Test Debug

    11/802013 FIT330 Software Engineering 11

    Test cases

    intGenerate TDSs

    Combine TDSs

    x1

    x2

    int[]

    a1

    a2

    a3

    a4

    a5

    ...

    Test cases someMethod(int x, int[] a)

  • 8/10/2019 Lect5 6a Test Debug

    12/802013 FIT330 Software Engineering 12

    0enerate T$s

    T$ is a sub-set o "alues o an input do'ain

    One input do'ain 'a* contain se"eral T$s

    teps to generate T$s:

    identi* the input ranges

    deine a T$ per range

    using representati"e data "alues

    x1

    x2

  • 8/10/2019 Lect5 6a Test Debug

    13/802013 FIT330 Software Engineering 13

    Techni.ues

    T#o techni.ues: blac-bo! testing (BBT)

    glass-bo! (a++a #hite-bo!) testing (0BT)

    BBT uses progra' speciication 0BT uses progra' te!t

  • 8/10/2019 Lect5 6a Test Debug

    14/802013 FIT330 Software Engineering 14

    Blac bo! testing

    How do we test this method ?

    /*** @effects* if a is null* tho!s "ull#ointe$x%e&tion* else if x is in a

    * etuns i su%h that a[i] ' x* else* tho!s "otound$x%e&tion*/publicstaticintsea%h(int[] a, intx)

    throws"ull#ointe$x%e&tion, "otound$x%e&tion

  • 8/10/2019 Lect5 6a Test Debug

    15/802013 FIT330 Software Engineering 15

    Other e!a'ples: st

    /*** @requires x >' ++ .1 < e&silon < .1* @effects etun n su%h that* xe&silon < n-2

  • 8/10/2019 Lect5 6a Test Debug

    16/80

  • 8/10/2019 Lect5 6a Test Debug

    17/80

    2013 FIT330 Software Engineering 17

    BBT: input range criteria

    re.uires: constraint e!pressions eects:

    output conditions

    e!ceptional conditions

    1onsider relationships bet#een inputs ineects

    Written using se'i-inor'al set notation

    nu'ber range notation

  • 8/10/2019 Lect5 6a Test Debug

    18/80

    2013 FIT330 Software Engineering 18

    sea%h

    /*** @effects* if a is null* tho!s "ull#ointe$x%e&tion* else if x is in a

    * etuns i su%h that a[i] ' x* else* tho!s "otound$x%e&tion*/publicstaticintsea%h(int[] a, intx)

    7anges: a: 8null9, 8;9 < 8x

    1,...,x

    n; = x

    iare integers9

    x: 8= * in a9 < 8= not in a9

  • 8/10/2019 Lect5 6a Test Debug

    19/80

    2013 FIT330 Software Engineering 19

    st

    /*** @requires x >' ++ .1 < e&silon < .1

    * @effects etunn su%h that

    * xe&silon < n-2

  • 8/10/2019 Lect5 6a Test Debug

    20/80

    2013 FIT330 Software Engineering 20

    is#ime

    /*** @effects* if & is a &ime* etuns tue* else

    * etuns false*/publicstaticbooleanis#ime(int&)

    7anges:

    pri'es: 8A,,C,5,+++9 non-pri'es: 8D,6,E,F,+++9

  • 8/10/2019 Lect5 6a Test Debug

    21/80

    2013 FIT330 Software Engineering 21

    BBT: T$ or'ation criteria

    @or each range use: data t*pe (incl+ arra*)

    t*pical and at*pical data o the t*pe

    0tindata t*pe: treated as an arra*-t*pe

    Other t*pes (later):

    iterator

    data abstraction t*pe hierarch*

  • 8/10/2019 Lect5 6a Test Debug

    22/80

    2013 FIT330 Software Engineering 22

    T*pical "s+ t*pical data

    u'eric data t*pe: t*pical: a e# nu'bers in the range

    at*pical: s'allest and largest "alues o the range

    rra* data t*pe: t*pical: arra*s containing a e# ele'ents

    at*pical:

    null, e'pt*, one-ele'ent arra* arra*s containing no#n "alues at speciic indices

  • 8/10/2019 Lect5 6a Test Debug

    23/80

    2013 FIT330 Software Engineering 23

    T$ e!a'ples: sea%h

    7anges: a: 8null9, 8;9 < 8x

    1,...,x

    n; = x

    iare integers9

    x: 8= * in a9 < 8= not in a9

    T$(s): a: 8null, ;, A;, C,A;, C,A,D;, C,5,A,D;9

    x: 8A,9

  • 8/10/2019 Lect5 6a Test Debug

    24/80

    2013 FIT330 Software Engineering 24

    st

    7anges: x: >,>>>A, +>>A)

    T$(s): x: 8>, >+>>A, >+>A, >+>F, >+5,

    A, , A>, A>>, ADGDEC6>>9

    e&silon: 8+>>>>, +>>>A, +>>>F9

    y?

  • 8/10/2019 Lect5 6a Test Debug

    25/80

    2013 FIT330 Software Engineering 25

    is#ime

    7anges: pri'es: 8,C,5,+++9

    non-pri'es: 8D,6,E,F,+++9

    T$(s): pri'es: 8,C,5,CA,655CG9

    non-pri'es: 8D,C,655CE9 y?

  • 8/10/2019 Lect5 6a Test Debug

    26/80

    2013 FIT330 Software Engineering 26

    BBT pros & cons

    d"antages: ease T1 generation

    robust against i'ple'entation changes

    ease result interpretation $isad"antages:

    path inco'plete i speciication is la#ed,inco'plete or not obser"ed

  • 8/10/2019 Lect5 6a Test Debug

    27/80

    2013 FIT330 Software Engineering 27

    0lass bo! testing

    staticintmaxfhee(intx,int,int) if(x > ) if(x > ) returnx6 elsereturn6 7 else

    if( > ) return6 elsereturn6

    77

    How do we test this method ?

  • 8/10/2019 Lect5 6a Test Debug

    28/80

    2013 FIT330 Software Engineering 28

    0BT: input range criteria

    Use the logic paths ound in: conditional

    loop

    recursion 1riteria:

    conditional e!pression

    nu'ber o iterations (loop & recursion onl*)

  • 8/10/2019 Lect5 6a Test Debug

    29/80

    2013 FIT330 Software Engineering 29

    1onditional

    if#(x) // do this

    elseif8(x)

    // do thatelse

    // do somethinelse

    7ange(s):

    all xs+t H(x)

    all xs+t I(x)

    all xs+t+ H(x) && I(x)

  • 8/10/2019 Lect5 6a Test Debug

    30/80

    2013 FIT330 Software Engineering 30

    /!a'ple: conditional

    staticintmaxfhee(intx,int,int) if(x > ) if(x > ) returnx6 elsereturn6 7 else // x

  • 8/10/2019 Lect5 6a Test Debug

    31/80

    2013 FIT330 Software Engineering 31

    deter'inistic loop

    staticintsomeMethod(intn) for(inti ' 16 i

  • 8/10/2019 Lect5 6a Test Debug

    32/80

  • 8/10/2019 Lect5 6a Test Debug

    33/80

    2013 FIT330 Software Engineering 33

    recursion

    staticintfa%t(intn) if(n < 1)

    return16

    else if(n '' 1)

    return16 else

    returnn * fact(n1)6

    7

    7ange(s) or n: (-3@,A)

    8A9

    (A,

  • 8/10/2019 Lect5 6a Test Debug

    34/80

    2013 FIT330 Software Engineering 34

    0BT: T$ or'ation criteria

    $epends on the range: conditional: data t*pe

    loopNrecursion: nu'ber o iterations & ter'ination

    7easonable nu'bers o iterations: loop: >, A,

    recursion: >, A (base), (inducti"e once), C(inducti"e t#ice)

    Ter'ination:

    ter'ination "alues

    include e!ceptional cases

  • 8/10/2019 Lect5 6a Test Debug

    35/80

    2013 FIT330 Software Engineering 35

    T$ e!a'ple: conditional

    staticintmaxfhee(intx,int,int) if(x > ) if(x > ) returnx6 elsereturn6 7 else // x

  • 8/10/2019 Lect5 6a Test Debug

    36/80

    2013 FIT330 Software Engineering 36

    deter'inistic loop

    staticintsomeMethod(intn) for(inti ' 16 i

  • 8/10/2019 Lect5 6a Test Debug

    37/80

    2013 FIT330 Software Engineering 37

    non-deter'inistic loop

    staticintsomeMethod(intx) while(x > ) // do somethin 7

    7

    7ange(s) or x:

    (-3@,>;

    A,,A,9 y?

  • 8/10/2019 Lect5 6a Test Debug

    38/80

    2013 FIT330 Software Engineering 38

    recursion

    staticintfa%t(intn) if(n < 1)

    return16

    else if(n '' 1)

    return16 else

    returnn * fact(n1)6

    7

    7ange(s) or n: (-3@,A)

    8A9

    (A,

  • 8/10/2019 Lect5 6a Test Debug

    39/80

    2013 FIT330 Software Engineering 39

    conditional & loop (A)

    staticintsomeMethod(intx) while(x > ) // %he%9s x modulo 1 if(x : 1 '' 5)

    break6 x6 77

    7ange(s) or x: (-3@,>; 8 * = * A> 9 8 * = * A> 9

    T$(s) or !: 8>, 5,A5,A,9 y?

  • 8/10/2019 Lect5 6a Test Debug

    40/80

    2013 FIT330 Software Engineering 40

    conditional & loop ()

    staticvoidmMethod(intn, intm) for(inti ' 16 i

  • 8/10/2019 Lect5 6a Test Debug

    41/80

    2013 FIT330 Software Engineering 41

    conditional & loop (): T$

    staticvoidmMethod(intn, intm) for(inti ' 16 i

  • 8/10/2019 Lect5 6a Test Debug

    42/80

    2013 FIT330 Software Engineering 42

    0BT pros & cons

    d"antages: useul #hen speciication is la#ed, inco'plete or

    not obser"ed

    aid code anal*sis and debug

    $isad"antages:

    re.uires no#ledge o the i'ple'entation

    not robust against i'ple'entation changes

  • 8/10/2019 Lect5 6a Test Debug

    43/80

    2013 FIT330 Software Engineering 43

    $e"elop and run tests

    Testing tass are repetitious

    @ull* auto'ated testing is diicult

    tep A is diicult to auto'ate

    speciications are not al#a*s precise

    Step 2can be auto'ated (our ocus here)

    using %Unit

    2b

  • 8/10/2019 Lect5 6a Test Debug

    44/80

    2013 FIT330 Software Engineering 44

    0eneral approach

    $e"elop test driversto: realise the test cases

    auto'ate the e!ecution o tests

    Test run run the test dri"er

  • 8/10/2019 Lect5 6a Test Debug

    45/80

    2013 FIT330 Software Engineering 45

    Test dri"er

    s'all progra' peciied as a data abstraction

    na'ing con"ention:xxxTest

    Tass include: initialise the T$s and test cases

    initialise the e!pected test results

    test each unit Use assertionto chec test results

    Pa* or' a t*pe hierarch*

  • 8/10/2019 Lect5 6a Test Debug

    46/80

    2013 FIT330 Software Engineering 46

    /!a'ple: dri"er or procedure

    One dri"er per procedure

    Test< s.uare7oot()

    SquareRootTest

  • 8/10/2019 Lect5 6a Test Debug

    47/80

    2013 FIT330 Software Engineering 47

    /!a'ple: dri"er or data abstraction

    One dri"er per class

    - tc3nt5et: int;;- tcRA: int;;- tcR: int;;

  • 8/10/2019 Lect5 6a Test Debug

    48/80

    2013 FIT330 Software Engineering 48

    3'ple'ent a test dri"er

    Use a third-part* pacage na'ed %Unit T#o "ersions:

    %Unit C+5: test dri"ers as sub-t*pes

    !"nit #$0(%d K A+5): test dri"ers as annotatedprocedures

  • 8/10/2019 Lect5 6a Test Debug

    49/80

    2013 FIT330 Software Engineering 49

    ssertion

    boolean state'ent "alidated auto'aticall* b*the run-ti'e en"iron'ent

    %a"a e*#ord: asset

    "ariants: asset$uals, asset;a$uals Usage:

    "alidate test results

    deensi"e progra''ing (later)

  • 8/10/2019 Lect5 6a Test Debug

    50/80

    2013 FIT330 Software Engineering 50

    ssertion e!a'ple

    nt0et s ' ... // initialise sassert(s.e&=() '' true)6

    assert(s.sie() '' 2) ?in@alid sie ?s.sie()6

    assertthat s.e&=is tre

    ot%erwisethro#s an ;ssetion$o

    assertthat shas t#o ele'entsot%erwisethro#s ;ssetion$o#ith 'essage in@alid sie ...

  • 8/10/2019 Lect5 6a Test Debug

    51/80

    2013 FIT330 Software Engineering 51

    Test dri"er or procedure

    a'ed ater the procedure Brie initial speciication onl*:

    no @ and rep in"ariant

    Test 'ethod: is annotated #ith Aest

    thro#s ;ssetion$o

    Pa* be para'eterised or each test case

  • 8/10/2019 Lect5 6a Test Debug

    52/80

    2013 FIT330 Software Engineering 52

    /!a'ple: 0uaeBootest

    %h1.Cunit4.0uaeBootest ote:

    arra*s are used to initialise

    test cases and results a or loop is used to run each

    test case

    use static 'ethod;sset.asset$uals

    toease assertion test

    Test< s.uare7oot()

    SquareRootTest

  • 8/10/2019 Lect5 6a Test Debug

    53/80

    2013 FIT330 Software Engineering 53

    peciication

    /**

    * @overview; test di@e fo the "um.st method*/publicclass0uaeBootest /**

    * @modifies0stem.out

    * @effects* fo ea%h test %ase t% ' < x,e, >* if D"um.st(x)-2 -2D > e* tho!s ;ssetion$o* else

    * dis&las "um.st(x) on the std out&ut *

    */ Aest publicvoidsuaeBoot() throws;ssetion$o7

    y?

  • 8/10/2019 Lect5 6a Test Debug

    54/80

    2013 FIT330 Software Engineering 54

    3'ple'entation

    Aest //(timeout ' 5) publicvoidsuaeBoot() throws;ssetion$o //... (%ode omitted) ...

    // test %ases

    float[] t%$&s ' .2f, .1f, .Ef 76

    float[] t%F ' f, .1f, .1f, .Ef, .5f,1f, 2f, 1f, 1f,214G4H3If 76

    // test esults float[] esults ' newfloat[t%F.lenth]6

    for(inti ' 6 i < t%F.lenth6 i) esults[i] ' (float) Math.sqrt(t%F[i])6

    76

  • 8/10/2019 Lect5 6a Test Debug

    55/80

    2013 FIT330 Software Engineering 55

    floatx,e,6 for(inti ' 6 i < t%F.lenth6 i) x ' t%F[i]6 ' esults[i]6 for(intC ' 6 C < t%$&s.lenth6 C) 0stem.out.&intln(?>>est %ase ?

    ((i*t%$&s.lenth)C))6 e ' t%$&s[C]6 floatesult ' "um.sqrt(x, e)6 // assume same delta eo J/! t!o esults assertEquals( * , esult * esult, 2 * e)6

    0stem.out.&intf(?st(:f,:f) ' :f ??(ex&e%ted ' :f) :n?, x, e, esult, )6

    7 7

    7 // end suaeBoot

    DE&'

  • 8/10/2019 Lect5 6a Test Debug

    56/80

    2013 FIT330 Software Engineering 56

    %h1.Cunit4.0uaeBootest

    H i d d i

  • 8/10/2019 Lect5 6a Test Debug

    57/80

    2013 FIT330 Software Engineering 57

    Hara'eterised test dri"er

    nnotated #ithABunKith(#aameteied.%lass)

    7ep deines a test case and e!pected output

    constructor to initialise rep #ith suitable args 'ethod to set up the test cases:

    annotated #ith A#aametes

    stati% return t*pe: Lolle%tion

    Test 'ethod operates directl* on the rep

    / lDE&'

  • 8/10/2019 Lect5 6a Test Debug

    58/80

    2013 FIT330 Software Engineering 58

    /!a'ple

    %h1.Cunit4.0uaeBoot#aameteisedest

    $ i i3

  • 8/10/2019 Lect5 6a Test Debug

    59/80

    2013 FIT330 Software Engineering 59

    $eensi"e progra''ing

    Being e!tra careul #hen progra''ing Three additional VchecsV:

    chec rep in"ariant

    chec the re.uires constraints e!hausti"e testing o all conditionals

    Use assertion to le!ibl* i'ple'ent the checs

    3

    Th th V h V

  • 8/10/2019 Lect5 6a Test Debug

    60/80

    2013 FIT330 Software Engineering 60

    The three VchecsV

    1hec rep in"ariant: i'ple'ents repOS

    1hec re.uires:

    checs input "alues against the pre-condition /!hausti"e testing o conditionals:

    co"ers all possible cases (including unspeciied)

    / l

  • 8/10/2019 Lect5 6a Test Debug

    61/80

    2013 FIT330 Software Engineering 61

    /!a'ple

    0tin s ' Lomm.receive

    ()6

    if(s.euals(?deli@e?))

    // %a out the deli@e euest

    7 elseif(s.euals(?examine?))

    // %a out the examine euest

    7

    / l d i

  • 8/10/2019 Lect5 6a Test Debug

    62/80

    2013 FIT330 Software Engineering 62

    /!a'ple: deensi"e

    0tin s ' Lomm.receive

    ()6

    if(s.euals(?deli@e?))

    // %a out the deli@e euest

    7 elseif(s.euals(?examine?))

    // %a out the examine euest

    7 else

    // handle eo %ase

    7

    U ti

  • 8/10/2019 Lect5 6a Test Debug

    63/80

    2013 FIT330 Software Engineering 63

    Use assertion

    0tin s ' Lomm.receive()6

    if(s.euals(?deli@e?))

    // %a out the deli@e euest

    7 elseif(s.euals(?examine?))

    // %a out the examine euest

    7 else

    // this %an ne@e ha&&en

    assertfalse6

    7

    / bl Ndi bl ti

  • 8/10/2019 Lect5 6a Test Debug

    64/80

    2013 FIT330 Software Engineering 64

    /nableNdisable assertions

    ssertions are disabled b* deault To enable (disable) use %PVs option ea(da)

    To enable assertions:Ca@a ea M#oam

    To disable assertions:

    Ca@a da M#oam

    $ i i i

  • 8/10/2019 Lect5 6a Test Debug

    65/80

    2013 FIT330 Software Engineering 65

    $eensi"e progra''ing issues

    7e.uire 'ore progra''ing eortect run-ti'e peror'ance

    eed to balance:

    code .ualit* costNti'e

    peror'ance

    $ b i#

  • 8/10/2019 Lect5 6a Test Debug

    66/80

    2013 FIT330 Software Engineering 66

    $ebugging

    To unco"er and correct bugs (errors) /!a'ine the inter'ediate states

    eed test cases that produce the bugs

    /icienc* depends on: design

    i'ple'entation

    docu'entation (e+g+ speciications)

    #

    $ b i t

  • 8/10/2019 Lect5 6a Test Debug

    67/80

    2013 FIT330 Software Engineering 67

    $ebugging steps

    @ind bug-producing T1s Locate bugg* code regions

    @i! bugg* code regions

    7etest progra' (regression testing)

    $ebugTestprogra'

  • 8/10/2019 Lect5 6a Test Debug

    68/80

    2013 FIT330 Software Engineering 68

    glo#-chart

    Debugging

    @ind bug-producing TCs

    (o)atebugg* code regions

    *i+bugg* regions

    bugg*?

    /nd test

    @ind bug producing T1s1

  • 8/10/2019 Lect5 6a Test Debug

    69/80

    2013 FIT330 Software Engineering 69

    @ind bug-producing T1s

    @or' a h*pothesis consistent #ith the testresult

    $esign and run tests that can reute theh*pothesis

    7epeat steps A & until a h*pothesis isestablished

    0enerate bug-producing T1s ro' the

    h*pothesis use t*picalNat*pical "alue rule

    1

    @lo# chart (A)

  • 8/10/2019 Lect5 6a Test Debug

    70/80

    2013 FIT330 Software Engineering 70

    @lo# chart (A)

    @or' a h*pothesis

    7eute h*pothesis "ia

    testing

    0enerate bug-producingT1s

    reuted?

    /!a'ple: (bugg*) "um sea%h

  • 8/10/2019 Lect5 6a Test Debug

    71/80

    2013 FIT330 Software Engineering 71

    /!a'ple: (bugg*) "um.sea%h

    7un 0ea%hest.sea%h 7un 0ea%hest.Ju0ea%h

    What are the bug-producing T1s ?

    nother (bugg*) "um sea%h

    http://data/projects/hanu/SEG/fall2013/java/src/ch10/junit4/SearchTest.javahttp://data/projects/hanu/SEG/fall2013/java/src/ch10/junit4/SearchTest.javahttp://data/projects/hanu/SEG/fall2013/java/src/ch10/junit4/SearchTest.javahttp://data/projects/hanu/SEG/fall2013/java/src/ch10/junit4/SearchTest.java
  • 8/10/2019 Lect5 6a Test Debug

    72/80

    2013 FIT330 Software Engineering 72

    nother (bugg*) "um.sea%h

    7un 0ea%hest.Ju0ea%h2 What are the bug-producing T1s ?

    Locate bugg* code regions2

    http://data/projects/hanu/SEG/fall2013/java/src/ch10/junit4/SearchTest.javahttp://data/projects/hanu/SEG/fall2013/java/src/ch10/junit4/SearchTest.java
  • 8/10/2019 Lect5 6a Test Debug

    73/80

    2013 FIT330 Software Engineering 73

    Locate bugg* code regions

    Trace the progra' #ith the T1s /!a'ine the inter'ediate results top-do#n

    $ata abstraction: chec procedure groups

    Hrocedure: chec re.uires 2 eects 1ode region: chec "ariables

    ided b* a debugger (e+g+ %a"a debugger)

    2

    @loat chart ()

  • 8/10/2019 Lect5 6a Test Debug

    74/80

    2013 FIT330 Software Engineering 74

    @loat chart ()

    Trace the !rogra"with the T#s

    E$a"ine inter"e%iate res&ts

    co%eregionfon%'

    (

    )

    *se a%e+gger

    $ebugDE&'

  • 8/10/2019 Lect5 6a Test Debug

    75/80

    2013 FIT330 Software Engineering 75

    $ebug

    %h1."um.sea%h Use /clipseVs debugger

    $ebug-runs 0ea%hest.Ju0ea%h

    What is the bug ?

    @i! bugg* code regions3

  • 8/10/2019 Lect5 6a Test Debug

    76/80

    2013 FIT330 Software Engineering 76

    @i! bugg* code regions

    1areull* anal*se each region 1o''on progra''ing pitalls:

    s*ntacticall* correct t*ping errors

    re"erse the order o input argu'ents loop one inde! too ar

    ail to reinitialise a "ariable

    inco'plete code cop*

    incorrect use o parentheses in an e!pression

    3

    $ebug guidelines (A)

  • 8/10/2019 Lect5 6a Test Debug

    77/80

    2013 FIT330 Software Engineering 77

    $ebug guidelines (A)

    Use a debugger (i one a"ailable)

    /nsure the right source code

    3'ple'ents sensible to0tin'ethods

    bug 'a* occur ar ro' its irst 'aniestation

    $eter'ine the progra' assu'ptions

    1hec careull* the input (against re.uires)

    /li'inate possible code regions

    0et help ro' others

    Tae a breaX

    $ebug guidelines ()

  • 8/10/2019 Lect5 6a Test Debug

    78/80

    2013 FIT330 Software Engineering 78

    $ebug guidelines ()

    Pae sure the bug 'atches its s*'pto's

    Understand #h* the bug occurred #here it is

    $eter'ine the i'pacts o code 'odiications

    u''ar*

  • 8/10/2019 Lect5 6a Test Debug

    79/80

    2013 FIT330 Software Engineering 79

    u''ar*

    Testing is a practical 'ethod o "alidating a progra'Vscorrectness

    Test cases are generated ro' speciication (BBT)andNor code (0BT)

    Test dri"ers are data abstractions i'ple'ented using%Unit

    $eensi"e progra''ing in"ol"es inserting checs todetect errors

    $ebugging is a 'ethod to unco"er bugs and correct theaected code regions

    Iuestions?

  • 8/10/2019 Lect5 6a Test Debug

    80/80

    Iuestions?


Recommended