YodasMyDad
YodasMyDad

Reputation: 9475

Visual Studio 2008 Testing A Method?

Now this might be a dumb question, but I'm still new to using Visual Studio 2008 but I was wondering if there is a feature like this (I'm using webforms ASP.NET C#).

I create a new method, highlight it in the editor and was wondering if there was a run/test method feature? Where it would exectute the method and prompt me via a UI for any variables the method might need to run?

I just thought this would really increase my productivity / speed in creating applications :S

Upvotes: 1

Views: 189

Answers (4)

Chris Marisic
Chris Marisic

Reputation: 33098

Take a look at Test Driven .NET this plugin adds functionality that you can right click a method and test it immediately. It's very useful.

Upvotes: 0

cfeduke
cfeduke

Reputation: 23226

I prefer to follow test driven development (TDD) when using Visual Studio - or any other language/IDE for that matter. Essentially you assert what you want your code to do by writing the unit test first, validate that the test fails, and then fill in the blanks in the method that you are testing. Its much easier to say than do, but once you're used to it, it becomes very natural and fast - not to mention your code has a lot less defects!

For a tool where you can test some code as you go, I recommend LinqPad (and there is also SnippetCompiler). While these don't let you highlight code and execute you can copy and paste into them achieving much of the same results.

For writing unit tests in VS you can use NUnit or any of its clones. I do not recommend the VS for Testers for unit testing.

I use NUnit in my current project and have become a fan of ReSharper for integrating the test suite into Visual Studio.

Upvotes: 2

AdaTheDev
AdaTheDev

Reputation: 147224

If you put your business logic in a separate class, you can use nunit to write proper, repeatable unit tests. www.nunit.org

Upvotes: 1

Konrad Rudolph
Konrad Rudolph

Reputation: 545518

You can use the console window in VS to test individual methods – provided the surrounding class compiles error-free. The console window can be activated via the View menu, IIRC.

Once inside the debug console, just enter the class name, followed by the method name (if it's a static method) or create an instance, if not. Printing the result can be done by prefixing the whole thing with ?, e.g.:

> ? MyFancyStringHelperClass.Reverse("Hello")
elloH

Upvotes: 1

Related Questions