How to test a class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am new to C# and VS.Net. How do I test inidividual classes? I'm used to Java where a Main method for every class to test it. However, VS sees each Main method as an entry point into the .exe. What is the standard procedure for debugging individual classes

Thanks
 
Try can NUnit.


Tom said:
I am new to C# and VS.Net. How do I test inidividual classes? I'm used to
Java where a Main method for every class to test it. However, VS sees each
Main method as an entry point into the .exe. What is the standard procedure
for debugging individual classes?
 
You can use NUnit for your unit test. Here is the URL to NUnit.

http://www.nunit.org/

To give you more idea, I have an automated build going that starts at
12:00a.m. every night for our product. I run NUnit during the automated
build. If NUnit fails, the automated build notifies me telling me what
failed. Implementing NUnit with our automated build has kept the quality of
our software to the next level.

Tom said:
I am new to C# and VS.Net. How do I test inidividual classes? I'm used to
Java where a Main method for every class to test it. However, VS sees each
Main method as an entry point into the .exe. What is the standard procedure
for debugging individual classes?
 
Tom.... Just as in Java, each class in C# can have a main for unit
testing.

http://www.geocities.com/jeff_louie/OOP/oop5.htm

5) The Visual Studio IDE Startup Object is Empty By Default

If the startup object string is empty and you declare more than one
"Main"
method in a Visual Studio project, the project will not compile. This is
very
frustrating. Trying to set the startup object property in the Visual
Studio IDE
is non-trivial. Let me save you some pain. To set the startup object,
select
View --> Solution Explorer. In the Solution Explorer window select the
name
of the project. Now select View --> Property Pages. (Do not select the
Property Window!) Alternatively, right click on the project name and
select
Properties. Now select the Common Properties folder in the left window.
You
can now select the appropriate startup object from the drop down list.
Don't
forget to click on "Apply."

Regards,
Jeff
to
Java where a Main method for every class to test it. However, VS sees
each
Main method as an entry point into the .exe. What is the standard
procedure
for debugging individual classes?<<
 
Tom said:
Jeff,

Thank you for the help and the good web site. I have another question -

Do you know if there is an option in VS.Net (2003), to run an individual class. In JBuilder, I had the option to run or debug any class that had a Main method. I was hoping VS had the same feature.

Tom

Unfortunately, no. You have to reset the 'Startup Object' property for
the project.

However, if you're using various different Main() instances for
debugging purposes like you used to in Java I'd recommend that you look
into using NUnit (http://www.nunit.org) instead.

There is also a good MSDN Magazine article on the subject:

http://msdn.microsoft.com/msdnmag/issues/04/04/ExtremeProgramming/
 
You can use the Main entry point to instanciate any other class -even in
the scenario that you have a two forms. Form1 with the Main as such
Application.Run (new Form2())

In practice I tend to copy the Main entry point and comment out the one I
dont want via /* ....*/
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
Tom said:
Jeff,

Thank you for the help and the good web site. I have another question -

Do you know if there is an option in VS.Net (2003), to run an individual
class. In JBuilder, I had the option to run or debug any class that had a
Main method. I was hoping VS had the same feature.
 
Back
Top