Unit and Acceptance Testing Kees Broenink Productions - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Unit and Acceptance Testing Kees Broenink Productions

Description:

Title: PowerPoint Presentation Last modified by: Kees Created Date: 1/1/1601 12:00:00 AM Document presentation format: Diavoorstelling Other titles – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 15
Provided by: keesbroen
Category:

less

Transcript and Presenter's Notes

Title: Unit and Acceptance Testing Kees Broenink Productions


1
Unit and Acceptance TestingKees Broenink
Productions
2
Unit and Acceptance Testing
  • Traditional categories
  • Unit OO class
  • Integration Sub system
  • System Database ...
  • Acceptance End user

3
Two criteria Unit Size and Reality
  • Size Reality
  • Unit small real
  • Integration medium mock
  • System total real
  • Acceptance total real

4
Mock testing is dangerous
  • Database errors are not taken into account
  • E.g. date format is not accepted
  • Remember the goal of testing
  • Invest on small but production like environments
  • E.g. MySql, setup/teardown helpers

5
Categories that make sense
  • Mock versus real life
  • Avoid mock
  • Use production like environments
  • Automatic versus manual
  • When automatic is possible invest on it!
  • End user (acceptance) versus unit (whatever size)
  • GUI always needs people to verify

6
Be efficient and avoid redundancy
  • Use top down approach
  • Start with biggest unit and move down
  • If no GUI start with acceptance testing
  • Unit testing useful for heavily used utility
    classes
  • In reality most utilities are delivered by
    third parties
  • Avoid abnormal input checking
  • Do not test on null if the method throws
    exception
  • Null problems must be found during development

7
Development null problems
  • public int calcProfit( Integer cost, Integer
    incoming)
  • if (costnull)
  • throw new NullPointerException
  • or
  • if (cost null)
  • return 0 WRONG (unit test is not the
    answer)
  • or just do it
  • return incoming.intValue() cost.intValue()

8
Case Study test HTTP application server
  • Goals
  • Real (no mock)
  • Tomcat the real server code is called
  • Automatic
  • batch utility (ant, nightly builds)
  • Highest possible unit
  • play the xhtml client (browser)
  • Useable for non-programmers
  • use simple declarative ASCII test specification
    files
  • Outside the scope
  • Acceptance of GUI
  • styling, clicking outside the use case, change
    url

9
Case Study main()
  • public class Runner
  • public static void main(String args)
  • File d new File(args0)
  • if (!d.isDirectory())
  • try
  • TestSpec.run(d)
  • catch (Exception e)
  • System.out.println(e.getMessage())
  • else
  • List list FileCollector.collectFiles
    (d, ".test",
  • new String "cvs" )
  • Iterator it list.iterator()
  • while (it.hasNext())
  • File script (File) it.next()
  • try
  • TestSpec.run(script)
  • catch (Exception e)
  • System.out.println(e.getMessag
    e())

10
Case Study declarative test specification
  • url http//localhost9090/datePicker/index.jsf
  • get
  • get
  • get, first extract the xmp tag and its children
    before comparing it
  • get filedatePicker/get.xml transform(fileget.xsl
    t)
  • post, click on a date in the first datepicker
  • req BackbaseClientDelta5Bevt3D_id17Cb3Aevent
    7Csubmit5D
  • post req filedatePicker/post.xml
  • post, click on button that wil change date of
    first one
  • req BackbaseClientDelta5Bevt3D_id37Cb3Aevent
    7Cclick5D
  • post req filedatePicker/post2.xml

11
Case Study TestSpec.run()
  • public static void run(File script) throws
    TestException
  • XMLUnit.setControlParser( "org.apache.xerces.j
    axp.DocumentBuilderFactoryImpl")
  • parse the file
  • executeRequests()
  • private static void executeRequests( List
    requests) throws Exception
  • HttpDialog dialog new HttpDialog()
  • Iterator it requests.iterator()
  • while (it.hasNext())
  • Request request (Request)it.next()
  • if (request.requestBody null) // must be
    GET
  • code dialog.get(request.urlString)
  • if (code ! 200)
  • throw new TestException(
    request.script, request.urlString, true, code)
  • if (request.expectedBody ! null)
  • result dialog.getResult()
  • if (request.response ! null)

12
Case Study HttpDialog
  • public class HttpDialog
  • HttpState state new HttpState()
  • String result null
  • public String getResult()
  • return result
  • public int get( String urlString, String body)
    throws Exception
  • int code 0
  • HttpConnection conn null
  • try
  • conn new HttpConnection(host,
    port)
  • HttpMethod method new
    GetMethod(url.getFile())
  • method.execute(state, conn)
  • code method.getStatusCode()
  • if (code 200)
  • result method.getResponseBodyAsS
    tring()
  • finally
  • try

13
Case Study expected result
  • ltxmp xmlns"http//www.w3.org/1999/xhtml"
  • xmlnsb"http//www.backbase.com/b"
    xmlnss"http//www.backbase.com/s"
  • id"index" style"displaynone"
    bbackbase"true"gt
  • ltscontrolpath bmatch"b" bvalue"/Backbase/3
    _1_4/controls/system/"/gt
  • ltsserver burl"/datePicker/index.jsf"
    bidentify"id" bmatch".jsf"/gt
  • ltsevent bon"construct"gtltstask
    baction"show"gtlt/staskgtlt/seventgt
  • ltbdatepicker id"_id2" binputstyle"background
    -colorbrown"
  • battsync"bdisabled,bvalue" bvalue""gt
  • ltsevent bon"change"gt
  • ltssuper/gt
  • ltstask baction"serversync"
    bevent"submit/gt
  • lt/seventgt
  • lt/bdatepickergt
  • ltbbutton id"_id3"gtchange date of first picker
  • ltsevent bon"command" bbubble"false"gt
  • ltstask baction"serversync"
    bevent"command/gt
  • lt/seventgt

14
Unit and Acceptance TestingKees Broenink
ProductionsEnd
Write a Comment
User Comments (0)
About PowerShow.com