使用 WinForms 和 NUnit 进行自动测试

发布于 2024-08-20 06:22:14 字数 512 浏览 2 评论 0原文

我使用 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 在调用时运行这些测试来自服务?

I'm using Cruise Control.NET and NAnt to automatically run NUnit tests on our code base. Some tests cause Windows forms to be shown. When these tests are run manually from VS or NUnit GUI, they work fine. When run via the Cruise Control service, I get the following exception:

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.

Short of excluding the test altogether or rewriting the test so the form is not shown, is there any other way I can modify the test or get NUnit to run these tests when called from a service?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘落散花 2024-08-27 06:22:14

您可以始终登录用户,并将服务附加到用户会话(如何创建交互式服务)。但是,最好修改代码和测试,这样 winform 的东西就被抽象了。

You can have always logged-in user, and attach the service to the user session(how to create interactive services). But, it's better if you modify your code and tests, so the winform stuff is abstracted.

開玄 2024-08-27 06:22:14

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

I usually mark such tests with attribute [Explicit] so they will only be run when I run them explicitly and not on the CCNET server. Other approach could be to mock up the behavior of the screen so there is no need to show it.

初与友歌 2024-08-27 06:22:14

您可以通过从命令行执行 CCNET 而不是将 CCNET 作为服务执行。

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

You might run those tests by executing CCNET from command line instead of executing CCNET as a service.

However I would recommend to keep different levels of testing apart from each other. If a test gets complicated i.e., it needs a more complex setting in order to run (e.g. special user interaction), this test is more an integration or acceptance test than a unit test (even if it uses NUnit).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文