views:

240

answers:

2

I have read many articles on the MVP pattern. Some folks say it is too complex and some say it's outdated. However to me it would seem like the perfect way to provide unit testing access to the UI - which is what I'm aiming to achieve.

Have you used MVP and if so what do you think?

+6  A: 

Model View Presenter, Model View Controller, traditional three tier (UI/Business Logic/Data Storage) or virtually any other architecture that isolates the various concerns of your code help you write tests.

Often the architecture is somewhat dictated by your tool: the Asp.Net MVP tags seem to indicate that you have already made your choice there. The trickiest part to test in any configuration is the UI, because even if you create a mock UI that performs all the functions the user can... at some point you will have to render it in a browser and assure yourself that the theory is sound.

Note that this does not discount the benefits of a mock presenter UI with unit tests that exercise all the options the user will have: doing so puts you light years ahead of someone doing straight UI testing alone. On the other hand, I have yet to find a program where the UI always rendered as we expected in every browser. Finding these cases still requires human intervention (or at best something like Selenium or Test Complete once you have the initial run-throughs).

Regarding the "obsolete" aspect, I think that is a red herring. There are of course religious wars regarding architectural choices, but the reason that MVP is being used in some ASP.NET projects is that there are quite a few who felt the traditional ASP.NET stack was too tightly integrated between the UI and the Business Logic. (I'm one of them.) For small projects that tight coupling isn't that big of a deal, and contributes to the quick "bring it up and running" ability of the form designer with databinding. In large projects, the limitations of these tools show up in a hurry, and having a "middle" tier hacked back in after the fact is a challenge: one you don't have to face with MVP.

Godeke
+1  A: 

I did an ASP.NET project using MVP last year. Yes, I was able to cover more with unit testing than I could before in the webforms world, but it felt hacky. Also, try explaining what you are doing to someone else. For some reason, people have a hard time grokking it. If I had to do it over again, I'd go with the ASP.NET MVC framework, since it is officially supported with tons of documentation and buzz, and not just a hack.

barneytron