473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to test a class

Tom
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
Nov 16 '05 #1
5 2034
Try can NUnit.
"Tom" <an*******@disc ussions.microso ft.com> wrote in message
news:95******** *************** ***********@mic rosoft.com...
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

Nov 16 '05 #2
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" <an*******@disc ussions.microso ft.com> wrote in message
news:95******** *************** ***********@mic rosoft.com...
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

Nov 16 '05 #3
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
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?<<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Tom wrote:
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/is...meProgramming/
--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
Nov 16 '05 #5
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" <an*******@disc ussions.microso ft.com> wrote in message
news:60******** *************** ***********@mic rosoft.com...
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

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2055
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally TestCase.skipIf(expr, msg): skips if expr is true These can be called either in setUp() or in the test methods. I also added reporting of skipped tests to TestResult, _TextTestResult and
4
3084
by: Edvard Majakari | last post by:
Hi, I just found py.test and converted a large unit test module to py.test format (which is actually almost-no-format-at-all, but I won't get there now). Having 348 test cases in the module and huge test classes, I started to think about splitting classes. Basically you have at least three obvious choises, if you are going for consistency in your test modules: Choise a:
0
2314
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the example source code can be downloaded here: http://www.blogitek.com/timhaughton/archives/files/User%20Interrogator%20And%20TDD.zip The article text is below. Not sure what it will do to the formatting when
5
2589
by: Dmitry Martynov | last post by:
Consider I have the following construction "if(x is T) ...". How much this test cost? And I wonder how it is implemented. Can I gain in performace if I introduce virtual methods like "bool isIt...()" in my base class and then call them instead of using is-operator?
6
2700
by: Ben Finney | last post by:
Howdy all, Summary: I'm looking for idioms in unit tests for factoring out repetitive iteration over test data. I explain my current practice, and why it's unsatisfactory. When following test-driven development, writing tests and then coding to satisfy them, I'll start with some of the simple tests for a class.
6
2648
by: ypjofficial | last post by:
HI, I have following terrific confusion. class test { public: int i; int * j; int **k;
3
3987
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing is having each form entry contained in a div, which as a label, an input with some event handlers,...
6
1940
by: Tony Johansson | last post by:
Hello!! If you write private class Test {} you have a private class If you write public class Test {} you have a public class If you write protected class Test {} you have a protected class If you write internal class Test {} you have a internal class Now to my question If you just write class Test {} what access is it then on the class Test meaning what is the default access.
5
6530
by: shuisheng | last post by:
Dear All, I was told that unit test is a powerful tool for progamming. If I am writing a GUI code, is it possible to still using unit test? I have a little experience in using unittest++. But I can not work out a way to use it to test GUI code. Thanks a lot!
176
8469
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write their own unit test framework, and then in a lab session see if I can get them to write their own. To give them an example I've created the following UTF class (with a simple test program following). I would welcome and suggestions on how anybody...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.