How to mock a member variable of dependency?
<p>I've got a class and member:</p>
<pre><code>class A
{
    B obj;
public:
    int f(int i){return obj.g(i);}
}
</code></pre>
<p>Here <code>B obj</code> is a dependency that requires run-time creation from a file. In my unit test for class A, I wish to mock <code>B obj</code>, with a function <code>g</code> typed <code>int(int)</code>.</p>
<p>How can I write my test code, to mock <code>B obj</code>, and then test <code>A::f</code>.</p>
<p>Thanks a lot.</p>