【发布时间】:2013-11-19 03:08:03
【问题描述】:
从事学校项目。只是为了好玩,我想知道是否可以使用单元测试中的 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 键的方法?
【问题讨论】:
标签: c# winforms unit-testing