【问题标题】:Can I run unit tests as a Windows application?我可以将单元测试作为 Windows 应用程序运行吗?
【发布时间】: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


    【解决方案1】:

    这不是单元测试,而是 UI 测试。那里有许多 UI 测试框架(我更喜欢 Microsoft 的 Coded UI)。

    unit 测试单独测试单个方法或类,这意味着它没有超出您控制范围的依赖项。如果您通过 UI 测试您的逻辑,那根本不是孤立的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 2013-12-11
      • 2015-07-25
      • 2016-02-10
      • 2011-07-09
      • 2013-03-20
      相关资源
      最近更新 更多