单元测试一个Windows的意见窗体应用程序 [英] Advice on Unit testing a Windows Forms application

查看:315
本文介绍了单元测试一个Windows的意见窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Windows窗体应用程序,现在我想为它编写一些单元测试(不完全测试驱动开发的看到,因为我写的测试中,我已经开发后,只有更好后期则永远!)我的问题是,随着这样的应用程序,你如何去写单元测试,因为几乎所有的方法和事件是私人的?我听说NUnit的形式,但我听到关于它的好和坏的东西,也出现了在该项目中没有真正的发展了一段时间,所以它看起来抛弃。也就是它普遍认为,该项目具有拥有充分的单元测试,如果我写的单元测试用例为所有的用户将通过点击/按下按钮触发事件,或者我会去编写单元测试用例全部?方法和想出一个办法来测试我的私有方法

I have written a Windows Forms application and now I want to write some unit tests for it (not exactly test driven development seeing as I am writing the tests after I have developed but better late then never!) My question is that with such an application how do you go about writing the unit tests, given that nearly all of the methods and events are private? I have heard of NUnit Forms but I hear good and bad things about it, also there has been no real development on that project for a while so it looks abandoned. Also is it generally accepted that the project have have adequate unit testing in place if I wrote unit test cases for all of the events that a user would trigger by clicking/ pressing buttons, or would I have to go and write unit test cases for all methods and figure out a way to test my private methods?

编辑:我的商业逻辑是从我的表现逻辑分开,有1或2 public方法我的商业逻辑暴露了这样的形式可以访问它们,但对所有的私有方法应该是在商业逻辑是什么?

My business logic is seperated from my presentation logic, there is 1 or 2 public methods my business logic exposes so the form can access them, but what about all the private methods that are in the business logic?

推荐答案

我会做的第一件事情是要确保你有你的业务逻辑的适当分离,从你的。基本上,使用 MVC模式。然后,你可以很容易的形式外检验一切,仿佛形式根本不存在。

The first thing I would do is to ensure that you have proper separation of your business logic from your from. Basically, using an MVC pattern. Then, you can easily test everything outside the form, as if the form didn't even exist.

现在,这仍然可以留下一些未经检验的具体形式的功能。即,是形式的有线到正确的服务?对于这一点,那么你可以仍然认为像NUnit的形式或另一种选择。

Now, this could still leave some untested form-specific functionality. I.E., is the form wired-up to the service correctly? For this, then you could still consider something like NUnit Forms or another alternative.

这篇关于单元测试一个Windows的意见窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆