I have a unit test class Tester
; I want it to access private fields of a Working
class.
class Working {
// ...
private:
Generally, your unit tests should not evaluate private variables. Write your tests to the interface, not the implementation.
If you really need to check that a private variable has a particular characteristic, consider using assert()
rather than trying to write a unit test for it.
A longer answer (written for C# rather than C++, but the same principles apply) is at https://stackoverflow.com/a/1093481/436641.