test first guis

Upload: neovik82

Post on 30-May-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Test First GUIs

    1/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    1

    Test First GUIsUsing Model-View-Presenter

    Robert Walsh - President - EnvisionWare, [email protected]

  • 8/14/2019 Test First GUIs

    2/51

  • 8/14/2019 Test First GUIs

    3/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    3Agenda

    What is Model-View-Presenter

    Benefits of MVP

    Implementing MVP

    Using MVP to Test User Interfaces

    Implementing MVP with Win32

    Summary

  • 8/14/2019 Test First GUIs

    4/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    4What isModel-View-Presenter?

  • 8/14/2019 Test First GUIs

    5/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    5What isModel-View-Presenter?

    A development technique for separating data,logic, display, and user interaction from one

    another Model holds data

    View displays data

    Presenterconnects the model to the view

    Presenter supplies the logic for manipulating the

    data and updating the display

  • 8/14/2019 Test First GUIs

    6/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    6What isModel-View-Presenter?

  • 8/14/2019 Test First GUIs

    7/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    7What isModel-View-Presenter?

  • 8/14/2019 Test First GUIs

    8/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    8

    User Input External Stimulus

    Notificationof change

    What isModel-View-Presenter?

  • 8/14/2019 Test First GUIs

    9/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    9

    Classic MVC doesnt work well with the modern rich clienttools because they design things so that the view handles allthe user events such as mouse and keyboard clicks. InModel View Presenter, the view continues to handle these,but then immediately delegates these to the presenter. Thepresenter then decides what to do with the event,

    communicating with the domain and the data in the viewscontrols.

    - Martin Fowler

    Source: http://www.martinfowler.com/eaaDev/ModelViewPresenter.html

    What isModel-View-Presenter?

    What about Model-View-Controller?

  • 8/14/2019 Test First GUIs

    10/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    10

    Upon further study and reflection, I decided that the patternthat was here under the name Model View Presenterneeded to be split, so I have seperated (sic) it intoSupervising Controller and Passive View. You can find adiscussion of the origins of Model-View-Presenter in thecontext of architecutres (sic) here:

    (http://www.martinfowler.com/eaaDev/uiArchs.html).

    - Martin Fowler, July 2006

    What is Model-View-Presenter?

    Additional comments from Martin Fowler

  • 8/14/2019 Test First GUIs

    11/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    11Benefits of MVP

  • 8/14/2019 Test First GUIs

    12/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    12Benefits of MVP

    Decoupling

    Business logic, data persistence, and user interface

    are kept isolated from one another Different teams may work on each part without

    depending on the other two

  • 8/14/2019 Test First GUIs

    13/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    13Benefits of MVP

    Flexibility

    Want a fresh new look?

    Change the View

    Model and Presenter remain unchanged

    Need to change how the data is stored?

    Change the Model

    View and Presenter remain unchanged

  • 8/14/2019 Test First GUIs

    14/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    14Benefits of MVP

    Re-use

    The same Model and Presenter might be used for a

    traditional thick client or for a web-based front-end

  • 8/14/2019 Test First GUIs

    15/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    15Benefits of MVP

    Testability

    Each component of the MVP triad may be tested

    independently from the other two Automated GUI testing is possible with scripts that

    rely on the layout of the interface

  • 8/14/2019 Test First GUIs

    16/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    16Implementing MVP

  • 8/14/2019 Test First GUIs

    17/51

  • 8/14/2019 Test First GUIs

    18/51

  • 8/14/2019 Test First GUIs

    19/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    19Implementing MVP

    The Presenter

    Holds references to the Model and the View

    Uses data from the Model to initialize the View

    User input is passed from the View to the Presenter,

    and the Presenter decides what to do with it

    Some user actions may cause the Presenter to

    update the Model

    Some external stimuli may cause the Model tonotify the Presenter that it should update the View

  • 8/14/2019 Test First GUIs

    20/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    20

    Presenter

    theView

    theModel

    ModelViewthePresenter

    Implementing MVP

  • 8/14/2019 Test First GUIs

    21/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    21Implementing MVP

    Psuedo-code for initializing an MVP triad

  • 8/14/2019 Test First GUIs

    22/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    22Implementing MVP

    Psuedo-code for the Presenters constructor

  • 8/14/2019 Test First GUIs

    23/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    23Using MVP to Test UserInterfaces

  • 8/14/2019 Test First GUIs

    24/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    24

    IPresenter

    theView

    theModel

    IModel

    IView

    thePresenter

    Presenter MockPresenter

    Model MockModel

    View MockView

    SensingView

    Using MVP to Test UserInterfaces

  • 8/14/2019 Test First GUIs

    25/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    25Using MVP to Test UserInterfaces?

    A simple example

  • 8/14/2019 Test First GUIs

    26/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    26Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    27/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    27Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    28/51

  • 8/14/2019 Test First GUIs

    29/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    29Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    30/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    30Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    31/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    31Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    32/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    32Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    33/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    33Using MVP to Test UserInterfaces?

  • 8/14/2019 Test First GUIs

    34/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    34Using MVP to Test UserInterfaces?

    If we are testing the Model

    The model can typically be tested through

    traditional unit testing processes The model typically does not interact directly with

    the View or the Presenter

  • 8/14/2019 Test First GUIs

    35/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    35Using MVP to Test UserInterfaces?

    The MVP approach allows the tester to simulateconditions that are difficult to induce the the

    real world Database errors

    Networking problems

    Exceptions

  • 8/14/2019 Test First GUIs

    36/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    36Using MVP to Test UserInterfaces?

    Key points

    What is being tested with MVP are the interactions

    between the Model, View, and Presenter The actual behaviors should be tested with each

    piece in complete isolation

    For example:

    Does view.setAddress(addressData) really

    set the text of the address control?

    Does model.getCustomer(customerId)

    really get customer information from the

    database?

  • 8/14/2019 Test First GUIs

    37/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    37Demonstration

  • 8/14/2019 Test First GUIs

    38/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    38Implementing MVP withWin32

  • 8/14/2019 Test First GUIs

    39/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    39Implementing MVP withWin32

    Win32 presents a challenge

    Traditional DlgProc does not function well in the role

    of the View The code handling the UI is procedural, not

    object-based

    Delegating input events to the Presenter is no

    problem, but allowing the Presenter to manipulate

    the View requires that the Presenter know more

    about the View than it should Specifically, the Presenter would have to know

    about the individual dialog controls and their IDs

  • 8/14/2019 Test First GUIs

    40/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    40Implementing MVP withWin32

    A solution

    Introduce a ViewProxy to serve as an interface

    between the DlgProc and the Presenter Input events will be handed to the ViewProxy, and

    the ViewProxy will hand them to the Presenter

    The Presenter will manipulate the ViewProxy, and

    the ViewProxy will manipulate the actual controls

    on the dialog

  • 8/14/2019 Test First GUIs

    41/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    41

    Presenter

    ModelView

    ViewProxy

    DlgProc

    Implementing MVP withWin32

  • 8/14/2019 Test First GUIs

    42/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    42Implementing MVP withWin32

  • 8/14/2019 Test First GUIs

    43/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    43Implementing MVP withWin32

  • 8/14/2019 Test First GUIs

    44/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    44Implementing MVP withWin32

  • 8/14/2019 Test First GUIs

    45/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    45Summary

  • 8/14/2019 Test First GUIs

    46/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    46Summary

    Model

    Represents data

    View

    Represents user interface

    Presenter

    Handles user input by interacting with the Model and

    updating the View

  • 8/14/2019 Test First GUIs

    47/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    47Summary

    Benefits

    Decoupling

    Data, logic, and presentation are separated Flexibility

    Persistence and look-and-feel are easily changed

    Re-use

    Models and Presenters may be used with multiple

    Views Testability

    Facilitates GUI testing at the Presenter and the

    View

  • 8/14/2019 Test First GUIs

    48/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    48Summary

    Implementation

    Presenter initializes View with data from Model

    View tells Presenter when user interacts with View

    Presenter gets information from Model and updates

    View

  • 8/14/2019 Test First GUIs

    49/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    49Questions

  • 8/14/2019 Test First GUIs

    50/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    50Resources

    Feathers, Michael (2002). Humble Dialog Box, The. [Online]. http://www.objectmentor.com/resources/articles/

    TheHumbleDialogBox.pdf

    Fowler, Martin (July 2004). Model View Presenter. [Online]. http://www.martinfowler.com/eaaDev/ModelViewPresenter.html

    Gamma, Erich et al. Design Patterns. Boston, MA: Addison-Wesley,1995.

    Lambert, Kenneth A. and Martin Osborne. Smalltalk in Brief Introduction to Object-Oriented Software Development. Boston, MA:PWS Publishing Company, 1997.

    Lewis, Simon. Art and Science of Smalltalk, The. London: Prentice HallInternational, 1995.

    Pinson, Lewis J. and Richard S. Wiener. Introduction to Object-Oriented Programming and Smalltalk, An. Reading, MA:Addison-Wesley, 1988.

  • 8/14/2019 Test First GUIs

    51/51

    Copyright2008-2009 Robert Walsh - All Rights Reserved

    51Thank you!

    For more information:

    Robert Walsh

    PresidentEnvisionWare, Inc.

    678-584-5911

    [email protected]://www.envisionware.com