如何在 Visual Studio 2010 中测试函数?
我编写了一个小函数,它接受字符串类型变量作为参数。
我想知道是否有什么方法可以测试我的功能?
我不想使用单元测试,因为它太过分了。
感谢您的回复。
更新
感谢大家的回复。
我的情况是,该函数将由事件处理程序触发。但是,我不想将句柄与我的函数绑定,我只想检查该函数是否有效。
那么最好的方法是编写单元测试吗?
I write a small function which accept a string type variable as parameter.
I am wondering if there is any way I can test my function?
I don't want to use Unit Test thing because it is overkill.
Thank you for your responses.
UPDATE
Thanks all for your replies.
My case is, this function will be trigger by an event handler. However, I don't want to bind the handle with my function and I just want to check if that function works.
So the best way is to write a unit test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
立即窗口
并在其中键入函数调用来进行测试。通常,人们会在运行应用程序时使用这个东西,但它也可以在设计时使用。You can use the
immediate window
and type the function call in there to test. Typically, one would use this thing while running an application, but it is also available at design time.这就是单元测试的用途。另一个选项是简单地创建一个新的控制台测试来引用它,但是只需右键单击它并创建一个新的单元测试很容易,而且最好的方法 - 它不是矫枉过正,需要 5 秒:)
最坏的情况只是删除你的测试当它完成时。
Thats what unit tests are for. The other option is simply create a new console test to reference it, however simply right clicking on it and creating a new unit test is easy, and the best method - it is not overkill and takes 5 seconds : )
Worst case just delete your test when its done.
您可以创建一个使用您的函数的示例应用程序,然后使用调试器单步执行它并验证一切是否正常工作。
但我必须同意 SLAks——你应该编写单元测试。事实上,这种方法听起来像是在乞求一些单元测试。
You could create a sample application that uses your function and then use the debugger to step through it and verify that everything is working correctly.
But I have to agree with SLaks - you should write unit tests. In fact, that kind of method sounds like it is begging for some unit testing.
我将使用 nunit 并创建一个类库并编写单元测试来测试功能。快速测试的传统方法是使用控制台应用程序,但不再建议这样做,因为单元测试被视为测试代码的快速且更具弹性的方法。
I would use nunit and create a class library and write unit tests to test the functions. A traditional way to quick test it is to use a console app, but this is no longer recommended as unit testing is seen as quick and more resiliant way to test code.