Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi 

i have a vb .net project where i have a protected friend method and i wanted to write a unittest for this.Unfortunately the design is like that and i am not allowed o change the architecture and i was supposed to write the unittest for it.

Can somebody please suggest whats wrong i am doing.


What I have tried:

i have tried adding the InternalsVisibleTo field to AssemblyInfo,vb file to my VB.Net project
<Assembly: InternalsVisibleTo("UnitTestAssemblyName")>


still i am not able to access my method in unittest
Posted
Updated 14-Aug-20 5:07am
Comments
Jin Vincent Necesario 14-Aug-20 7:56am    
You can do reflection to access the protected friend method.

1 solution

Hi
srinivas1221
,

You can create a derived class (Say Child) from this class (Your Class - where you cannot make any changes), and in derived class, you may elevate the access level to public for the method of interest and use objects of derived class for unit testing and asserting purposes.

Make sure you use this derived class only for purpose of testing. You may choose to create this derived class as private for your TestClass.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900