我可以将单元测试作为Windows应用程序运行吗?

时间:2013-11-19 03:08:04

标签: c# winforms unit-testing

参与学校项目。只是为了好玩,我想知道我是否可以使用单元测试中的SendKeys在WinForm上驱动事件。我有这些要求:

3. About Box
    a. Pressing the "F1" key on the keyboard shall display an about box window
    b. The about box window shall list the current software version and an email
         address for software support
    c. The about box window shall have a "OK" button
    d. Clicking the "OK" button shall close the about window

SendKeys适用于活动装配。单元测试位于程序的命名空间和表单中。当我在单元测试中尝试使用SendKeys时得到组件不接受消息的异常时,这意味着应用程序作为类库而不是Windows应用程序运行,对吧?有没有办法让测试作为Windows应用程序执行?

我猜我能做的最好的事情是从单元测试中创建我的表单实例并手动调用处理F1键的方法?

1 个答案:

答案 0 :(得分:1)

这不是单元测试,而是UI测试。有很多UI测试框架(我的偏好是Microsoft的Coded UI)。

unit 测试单独测试单个方法或类,这意味着它没有您控制之外的依赖项。如果你是通过用户界面测试你的逻辑,那根本就不是孤立的。