How do I test a private function or a class that has private methods, fields or inner classes?
Asked 07 September, 2021
Viewed 1.1K times
  • 59
Votes

How do I unit test (using xUnit) a class that has internal private methods, fields or nested classes? Or a function that is made private by having internal linkage (static in C/C++) or is in a private (anonymous) namespace?

It seems bad to change the access modifier for a method or function just to be able to run a test.

30 Answer