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

时间:2022-09-01 19:47:39

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开发。

6 个解决方案

#1


9  

You don't specify which flavor of VS2008 you are using. 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.

您没有指定您正在使用的VS2008的风格。如果它是Pro或者以上,那么MSTest是捆绑的,但是很多人都有它的问题 - 它并不总是非常直观,并且需要做太多的设置才能做一些简单的事情,比如覆盖/文件部署。

A walkthrough is here.

演练就在这里。

As a recommendation, I suggest using VS2008 with NUnit (free) and TestDriven.NET (not free). It takes away all the pain, allowing you to just write simple things like:

作为推荐,我建议使用VS2008和NUnit(免费)和TestDriven.NET(不是免费的)。它消除了所有的痛苦,允许你只写简单的东西,如:

[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. No messing with "testrunconfig" and the other files that MSTest wants you to use.

然后右键单击(在类上,在方法上,在项目上,在解决方案上)并使用TestDriven.NET提供的Test选项,包括(如果您有MSTest)“Test With - > Team Coverage”,使用MSTest覆盖工具运行NUnit测试,包括将颜色化返回到IDE以显示执行的行。没有搞乱“testrunco​​nfig”和MSTest希望你使用的其他文件。

#2


4  

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

Storefront and the Pair Programming videos involve a lot of TDD (Test Driven Development)

店面和配对编辑视频涉及大量TDD(测试驱动开发)

#3


1  

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. There are examples using nUnit as well as mocking frameworks such as Rhino.Mocks and Moq.

您没有指定是否正在使用Web / Windows应用程序,但如果您正在学习ASP.NET,那么Richard Dingwall与使用TDD的示例asp.net mvc应用程序有一些很好的链接。有一些使用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/

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/

Hope this helps!

希望这可以帮助!

#4


1  

The e-book Foundations of programming: http://codebetter.com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx

电子书编程基础:http://codebetter.com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx

also covers unit testing.

还包括单元测试。

#5


0  

If you interested in more than just normal unit-tests, then take a look at PEX

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

#6


0  

I would recommend looking at screencasts, to get a feel for how TDD is applied. At Dnr TV there are two episodes with JP Boodhoo, where he gives an introduction to test driven development:

我建议观看截屏视频,以了解TDD的应用方式。在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. This series shows the development of a fully unit tested application from start to finish.

如果你想看单元测试和TDD与其他一系列敏捷实践一起使用,我建议你观看一系列的“敏捷秋天”。本系列从头到尾展示了完全经过单元测试的应用程序的开发。

#1


9  

You don't specify which flavor of VS2008 you are using. 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.

您没有指定您正在使用的VS2008的风格。如果它是Pro或者以上,那么MSTest是捆绑的,但是很多人都有它的问题 - 它并不总是非常直观,并且需要做太多的设置才能做一些简单的事情,比如覆盖/文件部署。

A walkthrough is here.

演练就在这里。

As a recommendation, I suggest using VS2008 with NUnit (free) and TestDriven.NET (not free). It takes away all the pain, allowing you to just write simple things like:

作为推荐,我建议使用VS2008和NUnit(免费)和TestDriven.NET(不是免费的)。它消除了所有的痛苦,允许你只写简单的东西,如:

[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. No messing with "testrunconfig" and the other files that MSTest wants you to use.

然后右键单击(在类上,在方法上,在项目上,在解决方案上)并使用TestDriven.NET提供的Test选项,包括(如果您有MSTest)“Test With - > Team Coverage”,使用MSTest覆盖工具运行NUnit测试,包括将颜色化返回到IDE以显示执行的行。没有搞乱“testrunco​​nfig”和MSTest希望你使用的其他文件。

#2


4  

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

Storefront and the Pair Programming videos involve a lot of TDD (Test Driven Development)

店面和配对编辑视频涉及大量TDD(测试驱动开发)

#3


1  

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. There are examples using nUnit as well as mocking frameworks such as Rhino.Mocks and Moq.

您没有指定是否正在使用Web / Windows应用程序,但如果您正在学习ASP.NET,那么Richard Dingwall与使用TDD的示例asp.net mvc应用程序有一些很好的链接。有一些使用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/

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/

Hope this helps!

希望这可以帮助!

#4


1  

The e-book Foundations of programming: http://codebetter.com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx

电子书编程基础:http://codebetter.com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx

also covers unit testing.

还包括单元测试。

#5


0  

If you interested in more than just normal unit-tests, then take a look at PEX

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

#6


0  

I would recommend looking at screencasts, to get a feel for how TDD is applied. At Dnr TV there are two episodes with JP Boodhoo, where he gives an introduction to test driven development:

我建议观看截屏视频,以了解TDD的应用方式。在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. This series shows the development of a fully unit tested application from start to finish.

如果你想看单元测试和TDD与其他一系列敏捷实践一起使用,我建议你观看一系列的“敏捷秋天”。本系列从头到尾展示了完全经过单元测试的应用程序的开发。