Chapter 10. The Model-View-Presenter (MVP) Model

One of the biggest challenges in adopting Test-Driven Development and, ultimately, Continuous Integration is figuring out how to test the user interface (UI) portion of your application (if it has one). TestRunner applications that simulate user mouse and keyboard events are costly, difficult to set up, and often require learning a proprietary scripting language. Additionally, it is hard to integrate such tools into a Continuous Integration process because they are often not designed for XML reporting. In the chapter on testing, you learned about functional testing platforms such as Watir, but those only work with web-based applications (rather than with desktop applications).

There are strategies that you can pursue, however, which make it easier to test your user interface without relying on simulating user interactions. One such strategy has come to be called the Model-View-Presenter (MVP) model. MVP is a design pattern for UI-based applications that makes it much easier to automate testing of almost the entire application.

The fundamental strategy employed by MVP is to separate the bulk of the application from the very thinnest layer of the user interface. Everything but that very thin layer can then be tested using the same unit testing frameworks discussed in Chapter 5 ("Testing"), such as NUnit. The remaining thin slice of user interface code can then be quickly inspected visually by human testers with relatively little effort. ...

Get Code Leader: Using People, Tools, and Processes to Build Successful Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.