【翻译】Google - Testing on the Toilet - 有助于GUI测试的MVP框架
2010-03-08 12:13
706 查看
就像所有的体育项目发现丑闻都是后期,这些天很难找到好的角色模型。但是,当你的角色模型是一个域模型(业务实体对象模型),你不需要欺骗做一个MVP -
使用“模型视图主持人”模型!
MVP和MVC(模型视图控制器)非常相似。
MVC中,表示逻辑被控制器和视图共享,如下面的图所示。视图通常是直接继承自GUI框架的控件,观察模型的变化,并通过视图(GUI控件)显示模型的数据变化给用户。控制器负责决定如何转换用户事件到模型的更新。在MVP里,表示逻辑完全由“监督控制器”接管,也被称为“主持人”。
视图变成被动视图,代理给主持人。
主持人从模型里取出数据来更新视图。
这样分工可以是代码更加模块化,并且可以使针对主持人和视图的单元测试更加简单。
使用“模型视图主持人”模型!
MVP和MVC(模型视图控制器)非常相似。
MVC中,表示逻辑被控制器和视图共享,如下面的图所示。视图通常是直接继承自GUI框架的控件,观察模型的变化,并通过视图(GUI控件)显示模型的数据变化给用户。控制器负责决定如何转换用户事件到模型的更新。在MVP里,表示逻辑完全由“监督控制器”接管,也被称为“主持人”。
视图变成被动视图,代理给主持人。
public CongressionalHearingView() { testimonyWidget.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { presenter.onModifyTestimony(); // presenter decides action to take }}); }
主持人从模型里取出数据来更新视图。
public class CongressionalHearingPresenter { public void onModifyTestimony() { model.parseTestimony(view.getTestimonyText()); // manipulate model } public void setWitness(Witness w) { view.setTestimonyText(w.getTestimony()); // update view } }
这样分工可以是代码更加模块化,并且可以使针对主持人和视图的单元测试更加简单。
public void testSetWitness() { spyView = new SpyCongressionalHearingView(); presenter = new CongressionalHearingPresenter(spyView); presenter.setWitness(new Witness(“Mark McGwire”, “I didn't do it”)); assertEquals( “I didn't do it”, spyView.getTestimonyText()); }
相关文章推荐
- Google Testing on the Toilet系列---好的端对端测试是什么
- Google Testing:Testing on the Toilet: What Makes a Good End-to-End Test?
- A good idea: TotT – Testing on the Toilet
- [翻译Joel On Software]Joel测试:12步写出更高质量代码/The Joel Test: 12 Steps to Better Code
- 2016/2/26:Testing On the Toilet
- Test Driven Development and GUI Testing on the Android platform: Temperature Converter sample
- 初步了解Angular 2端到端的测试 Introduction to E2E Testing with the Angular CLI and Protractor
- XiaoMi/themis: Themis provides cross-row/cross-table transaction on HBase based on google's percolator.
- 利用google test 与QTest进行GUI 测试
- 软件测试自动化之路(8)----如何做更好的GUI Automation Testing
- How can I install the Google Apps Package (Play Store, ...) on my Android device?
- 【Android Api 翻译1】Android Texting(2)Testing Fundamentals 测试基础篇
- [翻译图书]-Moving Applications to the Cloud on the Microsoft Windows Azure Platform - 1
- 原创翻译:James Whittaker系列——Google是如何测试的(3)
- The art of software testing翻译--第二章(4)
- [gtest][001] A quick introduction to the Google C++ Testing Framework
- Selenium Testing Tools CookBook 翻译 ---Selenium 测试秘籍
- 原创翻译:James Whittaker系列——Google是如何测试的(1)
- android测试工具MonkeyRunner--google官网翻译
- 原创翻译:James Whittaker系列——Google是如何测试的(3)