Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm doing my first big project and I don't have a lot of experience in a professional programming environment. While researching anything programming-related I often see references to Unit Testing, but I am still unclear as to how to set those up or even if it would be beneficial to me.

Can someone explain unit testing to me, and how to set it up in a Visual Studio 2010 solution that has multiple projects? Is it something that occurs within your project's solution, or is it a separate solution? And is it something you'd recommend for a small development team or is it just a waste of time to setup?

Right now I just run the entire program to test whatever I am currently working on, but occasionally I have run into problems that are not easy to debug and it would be useful to run subsets of the code elsewhere... Sometimes I do setup another project with some of the libraries referenced to test a small part of the program, but I feel more time is wasted setting that up then just running the entire program because of all the dependencies involved

share|improve this question

1 Answer 1

up vote 15 down vote accepted

Setting up unit testing in VS2010 is fairly easy.

Add a new project to your solution and select the Test Project template from the New Project dialog box. Usually you create one test project for project you want to test in your solution (ie. BusinessLogic.proj would have a mate called BusinessLogicTest.proj, just as an example).

Once you have the project added, the easiest way (not necessarily the best way to do this, especially if you're goal is to get to TDD) to get started is to right-click on a function that you want to test and select "Create Unit Tests". Make sure the Output Project is the Test Project you just created and click OK. VS creates a new Test Class for you with a Test Method stubbed out.

That's the basics of getting setup. There's a lot to learn to test effectively, but you're at least on the right path by wanting to unit test. I'll see if I can find a demo or article to get you a bit further.

EDIT

Found one. This article is by Deborah Kurata (an MS MVP) and she has both C# and VB code samples. She is using VS2008, but the basics are the same for VS2010

share|improve this answer
1  
Thank you, that was exactly the sort of thing I wanted to get me started! Way easier than I thought it would be, and much faster then how I normally do it :) –  Rachel Sep 15 '10 at 14:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.