views:

415

answers:

5

I'm developing an ASP.NET 2.0 app using Visual Studio 2008.

If I want to run a really quick test on a method that's way in my back-end, is there a way for me to just call a main function in that class via command line?

Thanks

+5  A: 

That's what a test project is made for.

Mehrdad Afshari
+8  A: 

Short answer: NUnit. You may not know how to use it, but you should. It's not hard to use and learn. It's fast and has a GUI.

jcollum
Why is this downvoted?
Mehrdad Afshari
I get downvoted for suggesting unit testing? But the guy who says "test project" doesn't. Lame.
jcollum
Maybe I stole someone's answer and they're cranky about it?!
jcollum
I got down voted once on an accepted answer..its crazy
Perpetualcoder
That's happened a lot to me. Even once I closed an unrelated question and got downvoted on my top voted answers. You'll get used to it.
Mehrdad Afshari
Whoever down-voted this should be shot. Unit testing is the answer, not main methods
Randolpho
SO should REALLY consider requiring comments on downvotes.
Mehrdad Afshari
That might be a good idea, Mehrdad
Randolpho
The idea is good, but it was shot down on uservoice.
Sunny
Yeah I like the anonymity of downvotes. Plus 1 up = 5 down so no big.
jcollum
jcollum: considering the 200 point reputation limit/day, it hurts when your cap is full :)
Mehrdad Afshari
+1  A: 

Simply create a test project and test it from there. If not you can create a console application and test it from there by referencing the proper project(considering your code to test is in an assembly), which in a way will be your test project.

Perpetualcoder
+2  A: 

The answer is no, You cannot do that. You can only have one main function per assembly.

The fact is, you shouldn't do testing like that. C# is not Java, regardless of its origin in Java.

Use NUnit or MSUnit and build unit tests instead. They'll test your methods for you without needing deployment to a website or anything like that. That's the best way to test a method. Here are some links:

NUnit

MSUnit

Randolpho
You can have one Main function per assembly? Well, you can have at most one entry point but not necessarily one main function. C# compiler provides a switch /main:<type> switch which sets the entry point to the specific type. This switch is configurable in VS project properties too.
Mehrdad Afshari
Sorry, I suppose I should have been more explicit. Yes, you can have more than one method named "Main" in an assembly, but you can only have one Main function entry point per assembly. Yes, it's switchable, but in truth (...)
Randolpho
(...) the Mr Grieves shouldn't do that for testing purposes. I remember learning one main per class as "the standard way to test your Java classes" back in the days before JUnit, but that's not the standard way these days. Unit Testing with a framework is the right way to go.
Randolpho
+4  A: 
hmemcpy