473,796 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing classes individually

I remember that in Java you can compile and run each class individually
as long as it contains the method "main". However, is this possible in
C# as well? I tried it a while ago but it didn't work.

Dec 22 '05 #1
6 1597
In that case, you would have to make a single project file for each class.

"Huy Hoang" <dr*****@gmail. com> schrieb im Newsbeitrag
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I remember that in Java you can compile and run each class individually
as long as it contains the method "main". However, is this possible in
C# as well? I tried it a while ago but it didn't work.

Dec 22 '05 #2

"Huy Hoang" <dr*****@gmail. com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I remember that in Java you can compile and run each class individually
as long as it contains the method "main". However, is this possible in
C# as well? I tried it a while ago but it didn't work.


I just wrote a simple class, then added a Main() method with the header:

static void Main(string[] args)

I then instantiated my class and added some test code in the Main() method.

Worked fine.

How did you try to do it?
Dec 22 '05 #3
Let's say I have a VS solution with 10 VC# applications, and this
Visual C# Class Library project with the following default files:

- AssemblyInfo.cs
- Class1.cs

I then add the Class Library project as a reference to all the other
projects. The other projects can instantiate the Class1.cs just fine.
However, to test the class "Class1" individually without writing test
projects, but just like Java with a main method, seems impossible in
Visual Studio .NET 2003.

In JBuilder I am able to right click a class, and build/run it (if it
contains the "main" method). But in Visual Studio there is only this
"(Re)build [Projectname]" and "(Re)build solution".

Dec 22 '05 #4
Huy..

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."

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

In VS2005 you can now just right click.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Dec 22 '05 #5
Huy Hoang <dr*****@gmail. com> wrote:
I remember that in Java you can compile and run each class individually
as long as it contains the method "main". However, is this possible in
C# as well? I tried it a while ago but it didn't work.


You can specify the startup object in a .NET project, but this is *not*
the best way of testing classes.

Instead, get hold of a unit testing framework (eg NUnit -
http://www.nunit.org) and use that. It makes it much easier to build
whole suites of tests and run them at will, with immediate feedback
about whether they've worked or not.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 22 '05 #6
Jeff,

Setting the startup object isn't that hard, indeed. It's just that this
way of working is very frustrating.
That's why I will avoid it.

Dec 23 '05 #7

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

Similar topics

4
3743
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is possible). Most of my programming these days involves using PHP for creating script files for automating tasks and procedures (locally), and also for anything that might be needed by our divisional Intranet (not a huge site by any stretch of the...
17
8297
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now with form elements that turn out to be arrays that have to be compared with one another! I have one form element, languages, a checkbox group. Beside each checkbox is a dropdown, proficiency (which will become proficiency alongside languages)....
3
2307
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules and classes. In most cases these dependencies end-up in external systems such as databases and OS. Overhead in designing systems with "could be stubbed" in mind is great, so in many cases dropped. I would appreciate if anyone interested in this...
3
2703
by: SnaiL | last post by:
Hi, guys. I am interested in C++ unit testing. I know only two methods how to test private class methods. 1) Declare friend class in the code. But I don't like this style because tests depends on the code. 2) Cheat compiler. We can do it by: #define private public #include "..."
4
1926
by: a | last post by:
I'm having trouble testing a custom object. I've tried many different approaches. One is shown below. The XML below shows the state of the object and I'm trying to test for that state, ie there are NO classes in the Classes collection (Classes) of the custom object. The conditional expression returns the error shown below it... =======================================================XML returned by
58
3564
by: nw | last post by:
Hi, I have been asked to teach a short course on testing in C++. Until now I have used my own testing classes (which from what I've seen seem similar to the boost unit testing classes). Considering I have a limited amount of time what do readers of this group think would be useful to cover in this course? Is boost the way to go? Sorry if this is off-topic in this group.
20
2448
by: earthwormgaz | last post by:
Hello, I'm after doing some C++ unit testing, I'm using CppUnit. I like the look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no good to me sadly. So, I have class A, and it uses classes B and C. B and C have methods A uses, but they're not virtual, and I don't want to hack the code so that they are just to allow Unit Tests to work. This means that inheriting from B and C to provide Mock classes is a non starter.
0
1381
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or functions that do your hardware/file access that always return known data (but remember to test for alpha and beta errors--make sure both valid and invalid data are handled correctly). That way you can test the client code that is accessing the...
10
3926
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about py.test and nose. Are there other options? Is there any kind of concensus about the best, or at least how they stack up to each other? Brendan
0
9527
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,...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
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
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
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
5441
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
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.