使用 NUnit 测试 Windows 窗体逻辑

发布于 2024-08-20 09:13:43 字数 280 浏览 2 评论 0原文

我正在深入进行单元测试,我想知道是否可以使用 测试对话框或表单的某些特殊功能NUnit。我尝试过 NUnitForms,但它缺乏良好的文档,而且似乎没有人维护该项目。这是真的吗?

如果您有任何测试 Windows 窗体的经验,请给我指出正确的方法。如有任何意见或信息,我们将不胜感激。谢谢你!

I'm diving into unit testing and I would like to know if it is possible to test some special functionality of a dialog or a form with NUnit. I have tried NUnitForms, but it lacks good documentation and seems that nobody is mantaining that project. Is it true?

If you have any experience testing Windows Forms, please point me in the right way. Any comments or information are appreciated. Thank you!

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

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

发布评论

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

评论(4

牵你手 2024-08-27 09:13:43

我在使用 NUnitForms 时也遇到同样的问题。我可以启动一个表单并单击一个按钮,但我不知道如何让对话框工作,而且我根本找不到太多相关信息。
我认为这个博客是最有用的:
http://blogs.msdn。 com/john_daddamio/archive/2006/11/06/getting-started-with-nunitforms.aspx

我必须在 app.config 中重新映射 NUnitForms 程序集才能使其与最新版本是这样的:

<configuration>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <dependentAssembly>
        <assemblyIdentity name="nunit.framework"
          publicKeyToken="96d09a1eb7f44a77"
          culture="neutral" />
        <bindingRedirect oldVersion="2.2.7.0" newVersion="2.5.2.9222" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

( http://duncanjasmith.blogspot.com/2007 /08/using-nunitforms-with-nunit-framework.html

我希望这个帖子能帮助我,但我可能仍然会尝试白色项目( http: //www.codeplex.com/white ).

I am having the same problem with NUnitForms. I can launch a form and click a button, but I can't figure out how to get dialogs working, and I can't find much about it at all.
I think this blog was the most useful:
http://blogs.msdn.com/john_daddamio/archive/2006/11/06/getting-started-with-nunitforms.aspx

I had to remap the NUnitForms assembly in my app.config to get it to work with the latest version like this:

<configuration>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <dependentAssembly>
        <assemblyIdentity name="nunit.framework"
          publicKeyToken="96d09a1eb7f44a77"
          culture="neutral" />
        <bindingRedirect oldVersion="2.2.7.0" newVersion="2.5.2.9222" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

( http://duncanjasmith.blogspot.com/2007/08/using-nunitforms-with-nunit-framework.html )

I'm hoping this thread will help me, but I might still try project white ( http://www.codeplex.com/white ).

稀香 2024-08-27 09:13:43

自动化 GUI 测试往往非常脆弱,我猜这就是 NUnitForms 没有被维护的原因(如果这是真的)。

省去自己的痛苦,看看应用设计模式,例如 模型视图控制器模型视图ViewModel。这将使您能够以更稳健的方式对 UI 逻辑进行单元测试。

Automated GUI testing tends to be very brittle, and I would guess that this is why NUnitForms isn't being maintained (if that is true).

Spare yourself the agony and look at applying design patterns such as Model View Controller or Model View ViewModel. This will allow you to unit test the UI logic in a much more robust manner.

简美 2024-08-27 09:13:43

我使用 .Net 3.0 及更高版本中的 UI 自动化框架取得了很多成功。我写了一个教程,可能帮助您入门。

I've had a lot of success using the UI Automation framework that comes as part of .Net 3.0 and later. I've written a tutorial that might help get you started.

独闯女儿国 2024-08-27 09:13:43

Ayende 制作了一个非常好的且易于理解的 MVC 框架示例,请参阅 他的博客上的此条目了解更多详细信息。它的工作原理是向您的应用程序添加一个非常轻量级的基础设施,自动为您将按钮连接到事件。

通过使用这种类型的框架,您被迫在视图中没有任何逻辑,而仅在演示器中。然后您可以轻松地对逻辑进行单元测试,而无需接触 WinForms。

我已经开始将 Effectus 移植到 .NET 2.0 和 WinForms,它位于 此处 如果你有兴趣。

There's a very good and easy to understand example of a MVC framework produced by Ayende, see this entry on his blog for more details. It's a works by adding a very light-weight infastructure to your application that wires up buttons to events automatically for you.

By using this type of framework you are forced to not have any logic in your View, only in your Presenter. Then you can easily unit test the logic without touching WinForms.

I've started a port of Effectus to .NET 2.0 and WinForms, it's here if your interested.

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