简体   繁体   English

初学者介绍Visual Studio 2008中的单元测试

[英]Beginners introduction to unit testing in Visual Studio 2008

I'm a self-taught developer and my experience is all in small applications that I've developed. 我是一名自学成才的开发人员,我的经验都是我开发的小应用程序。

I'm currently working on an application that I've made public, and I've realized that I need to start doing good unit testing to catch regressions and generally make sure everything works. 我目前正在开发一个我公开的应用程序,并且我意识到我需要开始进行良好的单元测试以获取回归并且通常确保一切正常。

I've read up on a previous question . 我已经阅读了上一个问题 I would like to know if there are any resources online specifically dealing with C# unit testing in Visual Studio 2008, preferably with examples. 我想知道是否有任何在线专门处理Visual Studio 2008中的C#单元测试的资源,最好是带有示例。

EDIT: I'm using Visual Studio 2008 Professional for Windows applications, no web development. 编辑:我正在使用Visual Studio 2008 Professional for Windows应用程序,没有Web开发。

You don't specify which flavor of VS2008 you are using. 您没有指定您正在使用的VS2008的风格 If it is Pro or above, then MSTest is bundled, but a lot of people have issues with it - it isn't always very intuitive, and it takes far too much setup to do simple things like coverage / file deployment. 如果它是Pro或者以上,那么MSTest是捆绑的,但很多人都有它的问题 - 它并不总是非常直观,并且需要做太多的设置才能完成覆盖/文件部署等简单的事情。

A walkthrough is here . 演练就在这里

As a recommendation, I suggest using VS2008 with NUnit (free) and TestDriven.NET (not free). 作为推荐,我建议使用VS2008和NUnit (免费)和TestDriven.NET (非免费)。 It takes away all the pain, allowing you to just write simple things like: 它消除了所有的痛苦,让你只需写下简单的东西:

[TestFixture]
public class Foo {
    [Test]
    public void Bar() {
        Assert.AreEqual(2, 1+1);
    }
}

Then just right-click (on the class, on the method, on the project, on the solution) and use the Test options that TestDriven.NET provides, including (if you have MSTest) "Test With -> Team Coverage", which runs your NUnit tests with the MSTest coverage tools, including giving the colorization back into the IDE to show which lines executed. 然后右键单击(在类上,在方法上,在项目上,在解决方案上)并使用TestDriven.NET提供的Test选项,包括(如果您有MSTest)“Test With - > Team Coverage”,使用MSTest覆盖工具运行NUnit测试,包括将颜色化返回到IDE以显示执行的行。 No messing with "testrunconfig" and the other files that MSTest wants you to use. 没有搞乱“testrunco​​nfig”和MSTest希望你使用的其他文件。

http://www.asp.net/learn/mvc-videos/ http://www.asp.net/learn/mvc-videos/

Storefront and the Pair Programming videos involve a lot of TDD (Test Driven Development) 店面和配对编辑视频涉及大量TDD(测试驱动开发)

You don't specify whether you're working on web/windows apps, but if you're learning ASP.NET as well then Richard Dingwall has some excellent links to example asp.net mvc applications that use TDD. 您没有指定是否正在使用Web / Windows应用程序,但如果您正在学习ASP.NET,那么Richard Dingwall与使用TDD的示例asp.net mvc应用程序有一些很好的链接。 There are examples using nUnit as well as mocking frameworks such as Rhino.Mocks and Moq. 有一些使用nUnit的例子以及模拟框架,如Rhino.Mocks和Moq。

Have a look at his blog post here for some links: 在这里查看他的博客文章,获取一些链接:

http://richarddingwall.name/2008/11/02/best-practice-dddtdd-aspnet-mvc-example-applications/ http://richarddingwall.name/2008/11/02/best-practice-dddtdd-aspnet-mvc-example-applications/

James Gregory posted a pretty good primer on unit testing in general here: 詹姆斯格雷戈里在这里发布了关于单元测试的非常好的入门:

http://blog.jagregory.com/2007/07/17/getting-with-it-test-driven-development/ http://blog.jagregory.com/2007/07/17/getting-with-it-test-driven-development/

Hope this helps! 希望这可以帮助!

如果您不仅仅对正常的单元测试感兴趣,那么请看看PEX

I would recommend looking at screencasts, to get a feel for how TDD is applied. 我建议观看截屏视频,以了解如何应用TDD。 At Dnr TV there are two episodes with JP Boodhoo, where he gives an introduction to test driven development: Dnr TV上有两集JP Boodhoo,在那里他介绍了测试驱动的开发:

If you want to see unit testing and TDD used together with a whole bunch of other agile practices, I would recommend watching the sceencast series Autumn of Agile . 如果你想看单元测试和TDD与其他一系列敏捷实践一起使用,我建议你观看一系列的“敏捷秋天” This series shows the development of a fully unit tested application from start to finish. 本系列从头到尾展示了完全单元测试应用程序的开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM