Visual Studio Unit Testing of Windows Forms

后端 未结 8 2085
既然无缘
既然无缘 2020-12-28 09:09

We\'re working on a project here in Visual Studio 2008. We\'re using the built-in testing suite provided with it (the Microsoft.VisualStudio.TestTools.UnitTesting namespace

8条回答
  •  悲&欢浪女
    2020-12-28 09:34

    I use the Passive View architecture as detailed here http://martinfowler.com/eaaDev/PassiveScreen.html

    Basically move all your code in the forms to a separate class called the xxxUI. The form then implements a IxxxUI interface and expose anything that the xxxUI class needs. You can probably simplify things and aggregate dealing with several controls into one method.

    The flow then goes The USER click on a button. The button calls a method on the corresponding UI class. Passing any needed parameters. The UI Class method modifies the model. Then using the interface updates the UI.

    For unit testing you have test or dummy classes implement the interfaces and register themselves with the UI Classes. You can have these test classes fire any type of input and respond accordingly. Typically I have sequence lists that do thing in a precise order. (Tap A, click this, scroll that, then Type B, etc).

提交回复
热议问题