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.
我已经阅读了很多关于MVP模式的文章。有些人说这太复杂了,有人说它已经过时了。然而对我来说,这似乎是提供单元测试访问UI的完美方式 - 这正是我的目标。
Have you used MVP and if so what do you think?
你有没有使用MVP,如果有的话你怎么看?
2 个解决方案
#1
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.
模型视图演示者,模型视图控制器,传统的三层(UI /业务逻辑/数据存储)或几乎任何其他架构,可隔离代码的各种问题,帮助您编写测试。
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.
通常,架构在某种程度上取决于您的工具:Asp.Net MVP标签似乎表明您已经在那里做出了选择。在任何配置中测试的最棘手的部分是UI,因为即使你创建了一个模拟UI来执行用户可以执行的所有功能......在某些时候你必须在浏览器中渲染它并确保理论是声音。
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).
请注意,这并不会影响模拟演示者UI与单元测试的好处,这些单元测试会运用用户将拥有的所有选项:这样做可以让您比单独进行直接UI测试的人领先几年。另一方面,我还没有找到一个程序,其中UI总是按照我们在每个浏览器中的预期呈现。找到这些案例仍然需要人工干预(或者最好是像Selenium或Test Complete一样,一旦你有了初步的贯穿期)。
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.
关于“过时”方面,我认为这是一个红色的鲱鱼。当然有关于架构选择的宗教战争,但是在一些ASP.NET项目中使用MVP的原因是有很多人认为传统的ASP.NET栈在UI和业务逻辑之间过于紧密集成。 (我就是其中之一。)对于小型项目来说,紧密耦合并不是什么大不了的事,并且通过数据绑定有助于快速“提升并运行”表单设计器的能力。在大型项目中,这些工具的局限性显得匆匆而过,并且在事实成为挑战之后将“中间”层重新入侵:你不必面对MVP。
#2
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.
我去年使用MVP做了一个ASP.NET项目。是的,我能够在webforms世界中使用单元测试来覆盖更多,但它感觉很糟糕。另外,尝试向其他人解释你在做什么。出于某种原因,人们很难解开它。如果我不得不重新做一遍,我会选择ASP.NET MVC框架,因为它正式支持大量的文档和嗡嗡声,而不仅仅是一个黑客。
#1
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.
模型视图演示者,模型视图控制器,传统的三层(UI /业务逻辑/数据存储)或几乎任何其他架构,可隔离代码的各种问题,帮助您编写测试。
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.
通常,架构在某种程度上取决于您的工具:Asp.Net MVP标签似乎表明您已经在那里做出了选择。在任何配置中测试的最棘手的部分是UI,因为即使你创建了一个模拟UI来执行用户可以执行的所有功能......在某些时候你必须在浏览器中渲染它并确保理论是声音。
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).
请注意,这并不会影响模拟演示者UI与单元测试的好处,这些单元测试会运用用户将拥有的所有选项:这样做可以让您比单独进行直接UI测试的人领先几年。另一方面,我还没有找到一个程序,其中UI总是按照我们在每个浏览器中的预期呈现。找到这些案例仍然需要人工干预(或者最好是像Selenium或Test Complete一样,一旦你有了初步的贯穿期)。
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.
关于“过时”方面,我认为这是一个红色的鲱鱼。当然有关于架构选择的宗教战争,但是在一些ASP.NET项目中使用MVP的原因是有很多人认为传统的ASP.NET栈在UI和业务逻辑之间过于紧密集成。 (我就是其中之一。)对于小型项目来说,紧密耦合并不是什么大不了的事,并且通过数据绑定有助于快速“提升并运行”表单设计器的能力。在大型项目中,这些工具的局限性显得匆匆而过,并且在事实成为挑战之后将“中间”层重新入侵:你不必面对MVP。
#2
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.
我去年使用MVP做了一个ASP.NET项目。是的,我能够在webforms世界中使用单元测试来覆盖更多,但它感觉很糟糕。另外,尝试向其他人解释你在做什么。出于某种原因,人们很难解开它。如果我不得不重新做一遍,我会选择ASP.NET MVC框架,因为它正式支持大量的文档和嗡嗡声,而不仅仅是一个黑客。