I have never written/run a unit test. I am a relatively young programmer, but I do a LOT of reading. I've been searching for information on unit testing because I see a lot about, but I haven't come across anything that has really spelled it out for me from step 1.
我从未写过/进行单元测试。我是一个相对年轻的程序员,但我做了很多阅读。我一直在寻找有关单元测试的信息,因为我看到了很多,但我没有遇到任何从第1步开始为我拼写出来的东西。
I have Visual Studio 2005 Professional. I will be starting a new windows project in the next couple of days and I'd like to cut my unit testing teeth with this project, but I don't even know where to begin. I've seen sites that say VS2005 has unit testing built in, but upon following examples I see I don't have the same context menu content. Am I supposed to create a separate project or class? And what's this business about regression? Will the tests run every time I build?
我有Visual Studio 2005 Professional。我将在接下来的几天内开始一个新的Windows项目,我想用这个项目削减我的单位测试牙齿,但我甚至不知道从哪里开始。我见过网站上说VS2005内置了单元测试,但是根据以下示例,我看到我没有相同的上下文菜单内容。我应该创建一个单独的项目或类吗?关于回归的这项业务是什么?我每次构建时都会运行测试吗?
SO has a lot of great content about why to use unit testing so I'm hoping some members can provide or point me to a very thorough unit test installation-execution-results walk through.
SO有很多关于为什么要使用单元测试的很好的内容,所以我希望有些成员可以提供或指向我一个非常彻底的单元测试安装 - 执行结果。
6 个解决方案
#1
To unit test in Visual Studio 2005 you are going to need Team System, or a third-party unit test framework like nUnit.
要在Visual Studio 2005中进行单元测试,您将需要Team System或第三方单元测试框架,如nUnit。
There's a quick-start page for nUnit that can help you decide if nUnit is right for you. nUnit is similar to the built-in testing of Visual Studio 2008.
有一个nUnit的快速入门页面可以帮助您确定nUnit是否适合您。 nUnit类似于Visual Studio 2008的内置测试。
http://www.nunit.org/index.php?p=quickStart&r=2.5
You should also get TestDriven.net. TestDriven.net is a Visual Studio add-in that will integrate nUnit with Visual Studio.
您还应该获得TestDriven.net。 TestDriven.net是一个Visual Studio加载项,它将nUnit与Visual Studio集成在一起。
The Art of Unit Testing by Roy Osherove is a good book on unit testing. Roy Osherove is interviewed in a Scott Hanselman podcast here. The podcast is an excellent introduction to some of the principles and practices of unit testing:
Roy Osherove的单元测试艺术是一本关于单元测试的好书。 Roy Osherove在这里接受了Scott Hanselman播客的采访。该播客是对单元测试的一些原则和实践的精彩介绍:
#2
As much as I admire you for wanting to learn - can I respectfully urge you to stay away from mstest. As much as it seems easy at the start, mstest is not a good testing framework. It does simple things easily and possibly this will cover the learning case but more complex scenarios don't always work well with MS test philosophy. I'd really suggest you start with a simpler framework such as xunit, nunit, together with mocking ones such nmock and moq.
尽管我很佩服你想要学习 - 我可以恭敬地敦促你远离mstest。尽管一开始似乎很容易,但mstest不是一个好的测试框架。它很容易做到简单,可能会涵盖学习案例,但更复杂的场景并不总能与MS测试理念很好地配合。我真的建议你从一个更简单的框架开始,比如xunit,nunit,以及像nmock和moq这样的模拟。
Not only are these frameworks simpler to understand - they have massive communities behind them and getting help will be easier as a beginner.
这些框架不仅更易于理解 - 它们背后还有庞大的社区,作为初学者,获得帮助会更容易。
I agree with Robert Harvey's answer about The Art of Unit Testing by Roy Osherove.
我同意Robert Harvey关于Roy Osherove的单元测试艺术的回答。
#3
Visual Studio 2005 Professional does not have unit testing built in. I suggest you download the latest version of NUnit. You should create your tests in a separate project to your code. The tests won't run as part of your build, but you can create a build script that both compiles your code and runs the tests, using MSBuild, or NAnt.
Visual Studio 2005 Professional没有内置单元测试。我建议您下载最新版本的NUnit。您应该在与代码分开的项目中创建测试。测试不会作为构建的一部分运行,但您可以创建一个构建脚本,该脚本既编译代码又使用MSBuild或NAnt运行测试。
As for getting started with it, look for articles on unit testing with NUnit. You'll find them easier to find than ones on unit testing with Visual Studio.
至于开始使用它,请使用NUnit查找有关单元测试的文章。使用Visual Studio进行单元测试时,您会发现它们更容易找到。
#4
使用单元测试。
Also try http://social.msdn.microsoft.com/Search/en-US/?Refinement=26&Query=unit+test.
另请尝试http://social.msdn.microsoft.com/Search/en-US/?Refinement=26&Query=unit+test。
Those have little on 2005.
这些在2005年几乎没有。
Read Test-Driven Development in Microsoft .NET (Microsoft Professional), which is by James W. Newkirk and Alexei A. Vorontsov, two of the former developers of NUnit.
阅读Microsoft .NET(Microsoft Professional)中的测试驱动开发,这是由NUnit的两位前开发人员James W. Newkirk和Alexei A. Vorontsov撰写的。
#5
If need some visual aids and explanations check out dimecasts.net. They have a good selection of videos and they are fairly short.
如果需要一些视觉辅助和解释,请查看dimecasts.net。他们有很多视频选择,而且相当短。
I use the following tools to unit test (just in case you do not have access to team system):
我使用以下工具进行单元测试(以防您无法访问团队系统):
NUnit
RhinoMocks
NCoverage
R# - not free but a great tool all around
NUnit RhinoMocks NCoverage R# - 不是免费的,而是一个很棒的工具
#6
Another alternative for learning MSTest is to grab one of the trial versions of VS 2008 from here. I think the trial period is 90 days plenty of time to play around with it. Once you have it installed - we found the following blog posting and the document it references very helpful to getting started with VS 2008\MSTest based TDD.
学习MSTest的另一种方法是从这里获取VS 2008的试用版之一。我认为试用期是90天,有充足的时间来玩它。安装完成后 - 我们发现以下博客文章及其引用的文档对于开始使用基于VS 2008 \ MSTest的TDD非常有帮助。
#1
To unit test in Visual Studio 2005 you are going to need Team System, or a third-party unit test framework like nUnit.
要在Visual Studio 2005中进行单元测试,您将需要Team System或第三方单元测试框架,如nUnit。
There's a quick-start page for nUnit that can help you decide if nUnit is right for you. nUnit is similar to the built-in testing of Visual Studio 2008.
有一个nUnit的快速入门页面可以帮助您确定nUnit是否适合您。 nUnit类似于Visual Studio 2008的内置测试。
http://www.nunit.org/index.php?p=quickStart&r=2.5
You should also get TestDriven.net. TestDriven.net is a Visual Studio add-in that will integrate nUnit with Visual Studio.
您还应该获得TestDriven.net。 TestDriven.net是一个Visual Studio加载项,它将nUnit与Visual Studio集成在一起。
The Art of Unit Testing by Roy Osherove is a good book on unit testing. Roy Osherove is interviewed in a Scott Hanselman podcast here. The podcast is an excellent introduction to some of the principles and practices of unit testing:
Roy Osherove的单元测试艺术是一本关于单元测试的好书。 Roy Osherove在这里接受了Scott Hanselman播客的采访。该播客是对单元测试的一些原则和实践的精彩介绍:
#2
As much as I admire you for wanting to learn - can I respectfully urge you to stay away from mstest. As much as it seems easy at the start, mstest is not a good testing framework. It does simple things easily and possibly this will cover the learning case but more complex scenarios don't always work well with MS test philosophy. I'd really suggest you start with a simpler framework such as xunit, nunit, together with mocking ones such nmock and moq.
尽管我很佩服你想要学习 - 我可以恭敬地敦促你远离mstest。尽管一开始似乎很容易,但mstest不是一个好的测试框架。它很容易做到简单,可能会涵盖学习案例,但更复杂的场景并不总能与MS测试理念很好地配合。我真的建议你从一个更简单的框架开始,比如xunit,nunit,以及像nmock和moq这样的模拟。
Not only are these frameworks simpler to understand - they have massive communities behind them and getting help will be easier as a beginner.
这些框架不仅更易于理解 - 它们背后还有庞大的社区,作为初学者,获得帮助会更容易。
I agree with Robert Harvey's answer about The Art of Unit Testing by Roy Osherove.
我同意Robert Harvey关于Roy Osherove的单元测试艺术的回答。
#3
Visual Studio 2005 Professional does not have unit testing built in. I suggest you download the latest version of NUnit. You should create your tests in a separate project to your code. The tests won't run as part of your build, but you can create a build script that both compiles your code and runs the tests, using MSBuild, or NAnt.
Visual Studio 2005 Professional没有内置单元测试。我建议您下载最新版本的NUnit。您应该在与代码分开的项目中创建测试。测试不会作为构建的一部分运行,但您可以创建一个构建脚本,该脚本既编译代码又使用MSBuild或NAnt运行测试。
As for getting started with it, look for articles on unit testing with NUnit. You'll find them easier to find than ones on unit testing with Visual Studio.
至于开始使用它,请使用NUnit查找有关单元测试的文章。使用Visual Studio进行单元测试时,您会发现它们更容易找到。
#4
使用单元测试。
Also try http://social.msdn.microsoft.com/Search/en-US/?Refinement=26&Query=unit+test.
另请尝试http://social.msdn.microsoft.com/Search/en-US/?Refinement=26&Query=unit+test。
Those have little on 2005.
这些在2005年几乎没有。
Read Test-Driven Development in Microsoft .NET (Microsoft Professional), which is by James W. Newkirk and Alexei A. Vorontsov, two of the former developers of NUnit.
阅读Microsoft .NET(Microsoft Professional)中的测试驱动开发,这是由NUnit的两位前开发人员James W. Newkirk和Alexei A. Vorontsov撰写的。
#5
If need some visual aids and explanations check out dimecasts.net. They have a good selection of videos and they are fairly short.
如果需要一些视觉辅助和解释,请查看dimecasts.net。他们有很多视频选择,而且相当短。
I use the following tools to unit test (just in case you do not have access to team system):
我使用以下工具进行单元测试(以防您无法访问团队系统):
NUnit
RhinoMocks
NCoverage
R# - not free but a great tool all around
NUnit RhinoMocks NCoverage R# - 不是免费的,而是一个很棒的工具
#6
Another alternative for learning MSTest is to grab one of the trial versions of VS 2008 from here. I think the trial period is 90 days plenty of time to play around with it. Once you have it installed - we found the following blog posting and the document it references very helpful to getting started with VS 2008\MSTest based TDD.
学习MSTest的另一种方法是从这里获取VS 2008的试用版之一。我认为试用期是90天,有充足的时间来玩它。安装完成后 - 我们发现以下博客文章及其引用的文档对于开始使用基于VS 2008 \ MSTest的TDD非常有帮助。