Half a croissant, on a plate, with a sign in front of it saying '50c'
h a l f b a k e r y
The best idea since raw toast.

idea: add, search, annotate, link, view, overview, recent, by name, best, random

meta: news, help, about, links, report a problem

account: browse anonymously, or get an account and write.

user:
pass:
register,


         

priv to pub unit testing attribute

Turns a private method or property into public when compiled for unit testing
  (-2)
(-2)
  [vote for,
against]

The compiler knows nothing of this at programming time, so you get all the permissions correct under OO, but when you wish to unit test, you build and get access to each and every method.
pashute, Dec 31 2008

[link]






       Doable with reflection in C#. You can violate all public / private distinctions.
bigsleep, Dec 31 2008
  

       leave this set and you screw up your whole program in the most bizarre and dificult ways...
Voice, Dec 31 2008
  

       im not aware of a way to run unit tests which are external projects on private methods. The flag is ser only by that unit testing proj with its own attrib so no build problems should occur.
pashute, Jan 06 2009
  

       Ah. I can see what you are after now - the test-bed readily compiling and linking with the target methods without a lot of extra poking around e.g. Invoke( "TargetMethodName", param1, param2 ) etc.   

       Again, reflection could help to turn any assembly into a totally public assembly. This could be as a pre-build step to the test-bed. Still messy though.   

       I can't bun yet as I've never encountered this problem. If its complicated enough to be public it has a test that has decent code coverage. You could always build the test bed (if C#) into the module by using the 'internal' keyword rather than private. That would just leave you the problem of finding the test-bed entry point using reflection. Or other tricks using inheritence with protected methods.   

       I have to say though, that on the whole it needs to be a runtime setting as testing on any level assumes that what you are testing is fully equivalent to the shipped product i.e. binary compatible.   

       And after writing all that my nagging doubt has surfaced in the respect that you could well write a test-bed that proves everything works well but nobody can access anything.   

       All in all its probably better to use some other coding patterns like hidden constructors.
bigsleep, Jan 06 2009
  
      
[annotate]
  


 

back: main index

business  computer  culture  fashion  food  halfbakery  home  other  product  public  science  sport  vehicle