473,739 Members | 9,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unit Tests & access modifiers

I've just inherited a fairly large project with multiple classes. The
developer also wrote a huge number of unit tests (using NUnit) to validate
that the classes work correctly. However, I don't think that the class
itself should include unit tests, especially since it has to reference
nunit.framework in order to compile/work, and I don't want to have to
distribute the nunit.framework .dll with this class.

So I created a new project, moved the folder with all the unit tests to the
new project, and referenced the original project. When I compiled, I found
that the reason they were in the original project in the first place was
because the unit tests test a whole bunch of 'internal' classes.

Is there any way that I can split the unit tests into a separate project
and still let the unit tests compile and run?

This is .NET 1.1 - I think I recall something that we could do in .NET 2.0,
but I need it in .NET 1.1 as well.

TIA!

-mdb
Oct 27 '06 #1
6 2077
Michael,

This may help:

http://weblogs.asp.net/rosherove/arc...10/179515.aspx

Stephan

Michael Bray wrote:
I've just inherited a fairly large project with multiple classes. The
developer also wrote a huge number of unit tests (using NUnit) to validate
that the classes work correctly. However, I don't think that the class
itself should include unit tests, especially since it has to reference
nunit.framework in order to compile/work, and I don't want to have to
distribute the nunit.framework .dll with this class.

So I created a new project, moved the folder with all the unit tests to the
new project, and referenced the original project. When I compiled, I found
that the reason they were in the original project in the first place was
because the unit tests test a whole bunch of 'internal' classes.

Is there any way that I can split the unit tests into a separate project
and still let the unit tests compile and run?

This is .NET 1.1 - I think I recall something that we could do in .NET 2.0,
but I need it in .NET 1.1 as well.

TIA!

-mdb
Oct 27 '06 #2
"ssamuel" <ss*****@gmail. comwrote in news:1161976537 .359560.64900
@b28g2000cwb.go oglegroups.com:
http://weblogs.asp.net/rosherove/arc...10/179515.aspx
Might have worked, if I could actually download the file referenced in the
article... :(

Any other suggestions? It would be impractical to use either of the other
two solutions in the article. To start with the #1 Alternate doesn't
remove the requirement of referencing nunit.framework .dll, which is the
whole point of it anyway. And #2 would be difficult since I have over 200
unit tests, each in a separate file!

-mdb
Oct 27 '06 #3
Well, there's always the controversial idea that
http://c2.com/cgi/wiki?MethodsShouldBePublic

in short - if the method doesn't violate the class invariant, why not
make it make it public? And if it does, are you sure you want that
landmine lying around?

Michael Bray wrote:
I've just inherited a fairly large project with multiple classes. The
developer also wrote a huge number of unit tests (using NUnit) to validate
that the classes work correctly. However, I don't think that the class
itself should include unit tests, especially since it has to reference
nunit.framework in order to compile/work, and I don't want to have to
distribute the nunit.framework .dll with this class.

So I created a new project, moved the folder with all the unit tests to the
new project, and referenced the original project. When I compiled, I found
that the reason they were in the original project in the first place was
because the unit tests test a whole bunch of 'internal' classes.

Is there any way that I can split the unit tests into a separate project
and still let the unit tests compile and run?

This is .NET 1.1 - I think I recall something that we could do in .NET 2.0,
but I need it in .NET 1.1 as well.

TIA!

-mdb
Oct 27 '06 #4
Michael Bray wrote:
I've just inherited a fairly large project with multiple classes. The
developer also wrote a huge number of unit tests (using NUnit) to validate
that the classes work correctly. However, I don't think that the class
itself should include unit tests, especially since it has to reference
nunit.framework in order to compile/work, and I don't want to have to
distribute the nunit.framework .dll with this class.

So I created a new project, moved the folder with all the unit tests to the
new project, and referenced the original project. When I compiled, I found
that the reason they were in the original project in the first place was
because the unit tests test a whole bunch of 'internal' classes.

Is there any way that I can split the unit tests into a separate project
and still let the unit tests compile and run?

This is .NET 1.1 - I think I recall something that we could do in .NET 2.0,
but I need it in .NET 1.1 as well.

TIA!

-mdb
In 2.0 you can use he InternalsVisibl eTo Attribute which gives access to
all internal members of an assemblies.

In 1.1 you can take your UnitTests out in in your productional build
using conditional compilation.

BTW, even if you leave everything as it is, you don't have to deploy the
nunit.framework .dll. As long as nobody executes the test code the system
will not attemp to load it.

HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gm xNOSPAm.netNOSPAm
Oct 28 '06 #5
Michael Bray wrote:
I've just inherited a fairly large project with multiple classes. The
developer also wrote a huge number of unit tests (using NUnit) to validate
that the classes work correctly. However, I don't think that the class
itself should include unit tests, especially since it has to reference
nunit.framework in order to compile/work, and I don't want to have to
distribute the nunit.framework .dll with this class.

So I created a new project, moved the folder with all the unit tests to the
new project, and referenced the original project. When I compiled, I found
that the reason they were in the original project in the first place was
because the unit tests test a whole bunch of 'internal' classes.

Is there any way that I can split the unit tests into a separate project
and still let the unit tests compile and run?

This is .NET 1.1 - I think I recall something that we could do in .NET 2.0,
but I need it in .NET 1.1 as well.
I would view it slightly different.

Does it make sense to unit test the internal stuff
in an assembly ?

I would say that you unit test the exposed public interface
and do not worry about the internal encapsulated implementation.

Arne

Oct 29 '06 #6
as long as the users didn't actually run any unit tests you would only have
to compile the solution against the framework, you wouldn't have to include
it in your distro

"Michael Bray" <mbray@makeDInt oDot_ctiusaDcom wrote in message
news:Xn******** *************** *****@207.46.24 8.16...
"ssamuel" <ss*****@gmail. comwrote in news:1161976537 .359560.64900
@b28g2000cwb.go oglegroups.com:
> http://weblogs.asp.net/rosherove/arc...10/179515.aspx

Might have worked, if I could actually download the file referenced in the
article... :(

Any other suggestions? It would be impractical to use either of the other
two solutions in the article. To start with the #1 Alternate doesn't
remove the requirement of referencing nunit.framework .dll, which is the
whole point of it anyway. And #2 would be difficult since I have over 200
unit tests, each in a separate file!

-mdb

Oct 29 '06 #7

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

Similar topics

4
3740
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...
6
3684
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than writing the real functional code. My application manipulates graphs. I first write the skeleton in Python, then convert it to C++ for high performance (some graphs can have millions of nodes.)
14
2750
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
6
4405
by: Droopy | last post by:
Hi, I want to add unit tests in my application using NUnit. At first, I thought to add unit tests in the class that is tested, enclosed in a conditional attribute to remove these unit tests from release code. Though, there is (at least) 2 problems working like that : 1) the class can becoming very large if there is a lot of tests 2) when releasing, the NUnit dll should not be needed => it should not be referenced.
3
1221
by: Diego Park | last post by:
Hello, I am trying to generate tests for unmanaged C++ code, but I fail. Is that possible or am i doing something wrong? If so, where can I find a sample code? Thanks in advance. Best wishes, Diego Park
72
5264
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
5
6527
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!
6
5687
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly need following: 1. start/end timestamp for each test case (most important) 2. immediate report about exceptions (stacktrace) 3. it will be nice to use logging module for output
0
1241
by: noway001 | last post by:
Hi, I need to learn how to do unit tests for certain functions. I have googled and come accross some stuff, but all the examples are easy. I read multiple articles on code project, but it didn't help. Usually, I see examples of unit testings functions that take in 1-2 parameters and perform addition/multiplication/etc. I need to know how to unit test functions that return nothing, take in no parameters, and so on. For example, how do I...
0
8969
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
8792
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
9479
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
9266
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,...
1
6754
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
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
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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.