views:

217

answers:

6

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.

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?

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.

+4  A: 

To unit test in Visual Studio 2005 you are going to need Team System, or a third-party unit test framework like 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.

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.

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:

http://www.hanselminutes.com/default.aspx?showID=187

Robert Harvey
+1 for Roy's book, must read!
Jon Erickson
You don't need Team system for basic NUnit style unit tests in MSTest. In VS 2008 Pro its build in an works - but as in my answer don't do it.
Preet Sangha
A: 

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.

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.

David M
A: 

Working with Unit Tests.

Also try http://social.msdn.microsoft.com/Search/en-US/?Refinement=26&Query=unit+test.


Those have little on 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.

John Saunders
A: 

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.

Terence
+3  A: 

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.

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.

Preet Sangha
Unfortunately if you want to run any test using the COmpact Framework in the embedded area then MSTest seems to be the only choice :(
Liam Donaldson
A: 

If need some visual aids and explanations check out dimecasts.net. They have a good selection of videos and they are fairly short.

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

Miyagi Coder