Re: Testing friend/internal methods

"Kelly Anderson" <[email protected]> Wed, 6 Aug 2008 13:55:38 -0600
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
The standard answers are generally along these lines:

1) if you need it to be public to test it, then you NEED it to be
public because you NEED to test.

2) Test everything only through it's public interface. You don't need
to test internal classes if they are used by classes that you do test.
(Of course, that's a somewhat more integration test which is somewhat
less of a unit test)

3) Put the tests closer to the code (as you suggested)

4) Fear is the mind killer. (In other words, do what you need to do to
get the work done and stop worrying about it)

Enlightenment may begin with releasing yourself from feeling the
necessity to fear those things you cannot change.

-Kelly

2008/8/6 Christian Jordan <[email protected]>:
> Hello,
>
> I would like to test methods, that are declared as friend (vb) /
> internal (c#). I read older threats to this theme, and I know that
> placing the tests in the same project would help. But as you might
> understand, I want a separate testing-dll. Declaring these methods as
> public is another solution but after that I must remind me to set the
> visibility-level back to friend when I make a release. To my mind, that
> is not in the philosophy of unit-testing. Inheritance is another
> solution, but in this case i also have to change the visibility from
> friend to protected. And there are additional problems with constructors
> as well.
> Finally, I found the last solution to declare an assembly as "friend":
>
> 'Class to test
> Imports System.Runtime.CompilerServices
> <Assembly: InternalsVisibleToAttribute("AssemblyWithTest")>
> '...
>
> With this option, you can use friend-methods in the test-assembly.
> But unfortunately not in VB 2005. This is a well known problem with the
> VB-Compiler. OK, so I wrote the tests in C# and then the access to the
> method worked. But now I have other problems, for instance when I try to
> use a property. Although the test.dll (written in c#) compiles without
> errors, executing the test (that accesses methods written in VB) caused
> an exception:
>
> System.MissingMethodException : Methode nicht gefunden: Void
> Tranche.set_NameOfProperty(...).
>
> Maybe someone of you has a hint or a comment. If not, it is maybe better
> to say goodbye to testing friend / internal methods, but that would be a
> pity.
>
> Greetings
>
>
>
> Sitz der Gesellschaft: Hamburg; Amtsgericht Hamburg HRA 104052
> Persönlich haftende Gesellschafterin:
> LichtBlick Verwaltungsgesellschaft mbH; Amtsgericht Hamburg HRB 97446
> Geschäftsführer: Wilfried Gillrath, Heiko von Tschischwitz
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Nunit-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-users
>
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/