Search code examples
c#debuggingnunitaccess-modifiers

c#: public when debugging, private otherwise


Is there a nice way to make it so that functions are public when I am testing with NUnit, but private otherwise?

Not having to generate a lot of extraneous code would also be nice.

------------------------Edit------------------------

It seems the solutions fall under 3 types:

  1. don't do what I'm attempting to do.
  2. use compiler directives.
  3. try a clever solution (like using InternalsVisibleTo).

Might there be a way to do this programmatically? i.e. just create a new temporary app that makes all protected/private/internalfunctions public, plug that into NUnit, run the tests there, and then go back to using the private functions for the release version?


Solution

  • You might not need to if you have good coverage on your public methods which call the private methods but that seems to be another debate into it self.

    This is a good link about TDD and different ways to do it: How to Test Private and Protected methods in .NET