NUnit - tests in a separate project


M

Mark

Assume .NET 1.X and VS 2003 with NUnit. If you put the unit tests in a
different project, you can't test private or internal methods or classes.
We could put our unit tests in the same project, but it would be nice to put
them elsewhere. Are there work arounds for this issue?

Thanks in advance.

Mark
 
Ad

Advertisements

G

Giulio Petrucci

Mark ha scritto:
Assume .NET 1.X and VS 2003 with NUnit. If you put the unit tests in a
different project, you can't test private or internal methods or classes.
We could put our unit tests in the same project, but it would be nice to put
them elsewhere. Are there work arounds for this issue?

AFAIK unit tests *should* be placed in a different assembly, in order to
test only public(/protected) method/properties/classes. On my own I use
the debugger to test internal/private fields.

Kind regards,
Giulio
 
J

Jon Shemitz

Mark said:
Assume .NET 1.X and VS 2003 with NUnit. If you put the unit tests in a
different project, you can't test private or internal methods or classes.
We could put our unit tests in the same project, but it would be nice to put
them elsewhere. Are there work arounds for this issue?

Sure. Test your private and internal code via the public routines that
call them. ;-)

Alternately, you can use Reflection to access the private and internal
methods - by default, you have full access to all code on the local
machine.
 
R

RH

Jon Shemitz said:
Sure. Test your private and internal code via the public routines that
call them. ;-)

Alternately, you can use Reflection to access the private and internal
methods - by default, you have full access to all code on the local
machine.

I must agree with Jon. The public methods should be tested since those are
the ones that are going to be used by other binaries.
Testing internal methods is not worth the effort for the reward you're going
to get.
 
A

Alan J. McFarlane

Assume .NET 1.X and VS 2003 with NUnit. If you put the unit tests in
a different project, you can't test private or internal methods or
classes. We could put our unit tests in the same project, but it
would be nice to put them elsewhere. Are there work arounds for this
issue?
Thanks in advance.
In you main assembly add an attribute of the following form:

[assembly: InternalsVisibleToAttribute("Foo.Bar.Test,
PublicKey=9924000004800003453a63060356305305353405324543450f045034513045034563c453345e39503a1348573a53445b34653c45a03ecf6a339b6a179f513306cb9a33857107f1db3d6fa8a36564e778ae9a57fb74ed2b1840a6a2eab0f515dfa244fb521fd4a56057b1a4afc8c5b36df821239d717e618e4c2773719ab9034068974e4b95c40b2b566ba7a933221321fd123fd12f3d12fd3f12d3f21d282999")]
 
Ad

Advertisements

J

Jianwei Sun

Alan said:
Assume .NET 1.X and VS 2003 with NUnit. If you put the unit tests in
a different project, you can't test private or internal methods or
classes. We could put our unit tests in the same project, but it
would be nice to put them elsewhere. Are there work arounds for this
issue?
Thanks in advance.
In you main assembly add an attribute of the following form:

[assembly: InternalsVisibleToAttribute("Foo.Bar.Test,
PublicKey=9924000004800003453a63060356305305353405324543450f045034513045034563c453345e39503a1348573a53445b34653c45a03ecf6a339b6a179f513306cb9a33857107f1db3d6fa8a36564e778ae9a57fb74ed2b1840a6a2eab0f515dfa244fb521fd4a56057b1a4afc8c5b36df821239d717e618e4c2773719ab9034068974e4b95c40b2b566ba7a933221321fd123fd12f3d12fd3f12d3f21d282999")]
The OP says .Net 1.X and VS2003. I believe what you mentioned is .Net
2.0 new feature.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top