473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 1580
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.googlegr oups.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.googlegr oups.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.com>
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
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...
17
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...
3
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...
3
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...
4
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...
58
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)....
20
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...
0
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.