测试友好:C# WPF程序的面向测试的设计方式

基于Singleton的设计 vs 基于MEF/Unity的依赖注入设计

依赖注入方式使得自动化测试变得有些麻烦。所以目前还是采用基于Singleton的设计。

分层设计中的代码编写规范

根据《C# WPF桌面程序分层结构设计》。

不使用MEF等依赖注入技术的架构设计

  • Views,按功能划分组织用户控件文件
  • Business,业务逻辑
    应该可用于自动测试脚本静默运行。
  • 不应该包含任何MessageBox的弹出。
  • DAL,数据库ORM中间层
    应该可用于自动测试脚本静默运行。
  • 不应该包含任何MessageBox的弹出。
  • Infrastructure,基础架构工具
    应该可用于自动测试脚本静默运行。
  • 不应该包含任何MessageBox的弹出。

面向方面的设计

错误处理设计

Design pattern for including errors with return values

WPF测试

Why AutomationProperties are needed in WPF

Question:
As per my understanding, AutomationProperties can be utilized to identify names of controls by UI Automation clients.
I want to understand need to create separate set of automation properties, and not using x:Name for the same purpose.
Answer:
Let’s think about a text box, in your application it is the PhoneNumberTextBox, and you also have a PhoneNumberLabel, and PhoneNumberValidationTick. These are then displayed inside of a group box with a label showing “Customer”
A blind person trying to use your application would like the screen reader to say “Customer Phone Number” when they tab into the text box, likewise a tester writing an automated UI test for your application would like to be able to find the text box that contains the “Customer Phone Number”.
Now what if your application has been translated to German…. Would the blind user not want the screen reader to say ”Kundentelefonnummer“?
Now imagine you change your app to use a PhoneNumberInputControl, you will likely want to change the names of the control in your code, but the tester would rather wish that the control name does not change….
So we need the concept of a name that is used by programs that try to walk the “important” logical controls of an application at run time and automate something about how a user interacts with the application.
Ian Ringrose answered Feb 12 '14 at 12:46

Common Mistakes should not Make

使用TAP(Task-based Asynchronous Pattern)

C#语言中定义了许多异步编程模型,包括IAsyncResult模式(Asynchronous Programming Model, APM),Event-based Asynchronous Pattern (EAP)。
TAP是一种新的设计模式,相对于其它模式:

  • APM模式需要定义BeginMethodName and EndMethodName methods
  • EAP模式中, a MethodName**Async** is required in addition to one or more events

在SO的一个问答中说,It also forces you to separate your background operation logic from your UI/ViewModel update code, which is a Good Thing.

SO的另一个问答中说:You may find my async
intro helpful, as well as the task based asynchronous pattern document.
For more information on the overhead of async
, I recommend the Zen of Async by Stephen Toub.
You probably also want to read "Should I Expose Asynchronous Wrappers for Synchronous Methods?" In short, the answer is "no."

提炼Bundle模块:一种WPF MVVM/MEF程序架构的优化设计

MVVM+MEF架构的一个缺点是:VIEW MODEL类以及直接相关的类做的事情太多,且不能作为独立代码进行单独测试,必须依赖于MEF容器(这就依赖于所有其它类的对象了)。本文介绍的设计方法解决了这个问题,使得新的功能开发更容易分工和测试。不过,本文尚需在TDD测试驱动开发、测试时使用mock等技术方面去寻找正确理论和实践,以求让Bundle方法找到自己的真实定位:是一种新方法,还是仅仅自己的方式,甚或比别人的方法还不如?


测试友好:C# WPF程序的面向测试的设计方式_第1张图片
图片发自App

测试友好:C# WPF程序的面向测试的设计方式_第2张图片
图片发自App

测试友好:C# WPF程序的面向测试的设计方式_第3张图片
图片发自App

你可能感兴趣的:(测试友好:C# WPF程序的面向测试的设计方式)