title: How to access private members in unit tests?
body: <p>While developing unit tests, accessing private members to check the internal state of the class can be necessary. Sometimes getter and setter functions are not available, sometimes they are not public.</p>
  
  <p>First method to handle that, writing a preprocessor define writes publis instead of private and protected. </p>
  
  <pre><code>#define protected public
  #define private public
  </code></pre>
  
  <p>Second method is making the test classes friends of the classes.</p>
  
  <pre><code>class test_foo {
  };
  
  class foo {
  private:
    int mem;
  
    friend class test_foo;
  };
  </code></pre>
  
  <p>A third method is creating public interface for test.</p>
  
  <pre><code>class foo {
  
  #if defined FOO_UNIT_TEST
  public:
    int get_mem() const;
  #endif
  
  private:
    int mem;
  };
  </code></pre>
  
  <p>Is there any other method except these methods? Every method has pros and cons. Which one can be thought as best practice?</p>
  
  <p>Thanks.</p>