Ask a questionAsk a question
 

AnswerIgnoring accessibility levels

  • Wednesday, September 30, 2009 10:26 AMABroadbent Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hey, currently I'm writing unit tests for a large project, and a problem has occured.  I need to test private, protected and internal classes in the project assembly, but I need to do it from a seperate assembly.

    The reasoning for this is, I don't want the project assembly to contain unit tests, as it will be being released to end users, but more importantly I don't want them there as  they will effectivly double the size of each project, making loading and linking times considerable longer.

    is there a way that I can get my test assembly to ignore the accessibility level system in the project assembly, without changing code in the project assembly?  If not, is there another way around this problem?

    Thanks fo any help,
    Andy

Answers

  • Monday, October 05, 2009 9:04 AMABroadbent Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Partial classes weren't really the answer, as it would still add additional testing methods to each class.

    I did however solve it using reflection.

    Thanks for your help ^_^

All Replies

  • Wednesday, September 30, 2009 3:17 PMVipul Patel - CLRMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Check out partial classes http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx if they meet your requirement
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Monday, October 05, 2009 9:04 AMABroadbent Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Partial classes weren't really the answer, as it would still add additional testing methods to each class.

    I did however solve it using reflection.

    Thanks for your help ^_^
  • Tuesday, October 13, 2009 5:06 PMDevlife3 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    If you use MSTest it has a feature called "Accessor".
    Basically if you have a class Calculator you can right click on the cliass and select Create Accessor.
    It will then create Calculator_Accessor in your test project that will give you strongly typed access to your private methods.
    Otherwise you can add an attribute to Assembly.cs:

    [assembly:InternalsVisibleTo("MyProjectTests")]