【问题标题】:Automatic testing with WinForms and NUnit使用 WinForms 和 NUnit 进行自动测试
【发布时间】:2010-02-06 16:33:52
【问题描述】:

我正在使用 Cruise Control.NET 和 NAnt 在我们的代码库上自动运行 NUnit 测试。某些测试会导致显示 Windows 窗体。当这些测试从 VS 或 NUnit GUI 手动运行时,它们可以正常工作。通过 Cruise Control 服务运行时,出现以下异常:

System.InvalidOperationException : Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

除了完全排除测试或重写测试以使表单不显示之外,还有其他方法可以修改测试或让 NUnit 在从服务调用时运行这些测试吗?

【问题讨论】:

    标签: nunit cruisecontrol.net


    【解决方案1】:

    您可以始终登录用户,并将服务附加到用户会话(how to create interactive services)。但是,如果你修改你的代码和测试会更好,所以 winform 的东西是抽象的。

    【讨论】:

      【解决方案2】:

      我通常用属性 [Explicit] 标记此类测试,因此它们只会在我显式运行它们时运行,而不是在 CCNET 服务器上运行。其他方法可能是模拟屏幕的行为,因此无需显示它。

      【讨论】:

      • 此属性可以添加到单个测试方法或完整的测试夹具中
      【解决方案3】:

      您可以通过 executing CCNET from command line 运行这些测试,而不是将 CCNET 作为服务执行。

      但是,我建议将不同级别的测试彼此分开。如果测试变得复杂,即它需要更复杂的设置才能运行(例如特殊的用户交互),则此测试更像是集成或验收测试而不是单元测试(即使它使用 NUnit)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-23
        • 2012-05-18
        • 2011-02-20
        • 2017-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多