私は2つのクラスを持っています。Google Mockヘルプが必要です。
class SomeClass
{
public:
int SomeFunction()
{
return 5;
}
};
class AnotherClass
{
public:
int AnotherFunction(SomeClass obj)
{
return obj.SomeFunction();
}
};
私はSomeClassのモッククラスを作成しました。
class MockSomeClass : public SomeClass
{
public:
MOCK_METHOD0(SomeFunction, int());
};
ここで私はAnotherClass.AnotherFunctionを呼び出すと自分で選択した結果が得られることをユニットテストで確認します。 AnotherFunctionはSomeClass.SomeFunction()の関数を使用します。私はSomeClassを嘲笑した。そして私はそれを設定しました。擬似オブジェクトの機能がそれを後退10と呼ぶときです。しかし、私がユニットテストを実行すると、5(元の関数)が返されます。私は何をすべきか。以下は私が書いたユニットテストです。
[TestMethod]
void TestMethod1()
{
MockSomeClass mock;
int expected = 10;
ON_CALL(mock, SomeFunction()).WillByDefault(Return(expected));
AnotherClass realClass;
int actual = realClass.AnotherFunction(mock);
Assert::AreEqual(expected, actual);
};
私はvisual studio 2008とgmock 1.6.0を使用しています。私は何をしているのですか。 realClass.AnotherFunctionでmock.SomeFunction()からの出力を嘲笑したい。
を使用して、それを呼び出します。それは動作しません。それでも10の代わりに5を返します。 –
@fhnaseer実際のコードを表示します。 –
ありがとうございました。参照を渡すことでそれを解決し、 –