Unit Testing Private Method in Resource Managing Class (C++) <p>I previously asked this question under another name but deleted it because I didn't explain it very well.</p> <p>Let's say I have a class which manages a file. Let's say that this class treats the file as having a specific file format, and contains methods to perform operations on this file:</p> <pre><code>class Foo { std::wstring fileName_; public: Foo(const std::wstring&amp; fileName) : fileName_(fileName) { //Construct a Foo here. }; int getChecksum() { //Open the file and read some part of it //Long method to figure out what checksum it is. //Return the checksum. } }; </code></pre> <p>Let's say I'd like to be able to unit test the part of this class that calculates the checksum. Unit testing the parts of the class that load in the file and such is impractical, because to test every part of the <code>getChecksum()</code> method I might need to construct 40 or 50 files!</p> <p>Now lets say I'd like to reuse the checksum method elsewhere in the class. I extract the method so that it now looks like this:</p> <pre><code>class Foo { std::wstring fileName_; static int calculateChecksum(const std::vector&lt;unsigned char&gt; &amp;fileBytes) { //Long method to figure out what checksum it is. } public: Foo(const std::wstring&amp; fileName) : fileName_(fileName) { //Construct a Foo here. }; int getChecksum() { //Open the file and read some part of it return calculateChecksum( something ); } void modifyThisFileSomehow() { //Perform modification int newChecksum = calculateChecksum( something ); //Apply the newChecksum to the file } }; </code></pre> <p>Now I'd like to unit test the <code>calculateChecksum()</code> method because it's easy to test and complicated, and I don't care about unit testing <code>getChecksum()</code> because it's simple and very difficult to test. But I can't test <code>calculateChecksum()</code> directly because it is <code>private</code>.</p> <p>Does anyone know of a solution to this problem?</p>