I have a solution with two projects within:
Company.Project.vbproj
Company.Project.Tests.vbproj
Within the Company.Project.vbproj assembly, I have a class FriendClass.vb which scope is Friend (internal in C#).
Now I wish to test this FriendClass.vb from within the Company.Project.Tests.vbproj assembly. I know about the InternalsVisibleToAttribute, but that is not an option in Visual Basic .NET 2.0, as it is only available with C#, in .NET 2.0 (see here).
I would like to create myself a proxy class using this internal FriendClass from within my testing assembly, so that I could instantiate it and do the testings accordingly.
Any idea or known practices to do so?
Thanks in advance! =)
The only workaround that I have found is one used back in .NET Framework 1.1.
As the
InternalsVisibleToAttributeis not useable in .NET 2.0 Visual Basic, the only workaround that I have found is to include my tests within the same project as my library itself. Besides, some further work needs to be accomplished.#if CONFIG = "Tests" then ... #end if;For example, if I have the following Friend class:
Then, if you want to test this class in .NET 2.0 Visual Basic, you will need to create a test class within the same project where the
MyFactoryclass sits. This class should look like so:Since you have a compiler directive telling the compiler to compile and to include this class only when the “Tests” CONFIG is selected, you won’t get this class on “Debug” or on “Release” mode. This class won’t even be part of the library, this for not polluting your library unnecessarily, and this allows you to test your Friend class anyway.
That is the smartest way I have found to work around this issue in Visual Basic .NET 2.0.