gmock


set EXPECT_CALL to redirect the call to the original method


I have a class with several methods that depend on each other. Lets say foo(), bar() and baz().
When I test bar() I need to mock the behavior of foo(), when I test baz() I need to mock the behavior of bar().
If I mock bar for baz I cannot use the same mock class to test bar with the mocked foo().
My question is can I set EXPECT_CALL to actually call the original behavior and how. This will eliminate the need to create several Mock classes.
Answer can be found in googlemock CookBook
In short, you need to write
class MockFoo : public Foo {
public:
// Mocking a pure method.
MOCK_METHOD1(Pure, void(int n));
// Mocking a concrete method. Foo::Concrete() is shadowed.
MOCK_METHOD1(Concrete, int(const char* str));
// Use this to call Concrete() defined in Foo.
int FooConcrete(const char* str) { return Foo::Concrete(str); }
};
and
ON_CALL(foo, Concrete(_))
.WillByDefault(Invoke(&foo, &MockFoo::FooConcrete));

Related Links

gmock ReturnRef returns compilation error
How to call function pointer which is passed to Mock method?
In gmock, Is there a way to have mock object return an instance of an user defined object?
GMock testing destructor calls
set EXPECT_CALL to redirect the call to the original method
Capture GMOCK string parameter
Mocking non-virtual method generating errors
gmock matcher doesn't match my arguments by reference
What did you do to solve gmock you mentioned (link enclosed)?
how to set custom ref-variable in gmock

Categories

HOME
embedded
oracle12c
string
gradient
spring-data-mongodb
scripting
gembox-spreadsheet
project
appcelerator-studio
mod-security
scrolltop
docx
symbol
screen-readers
gruntfile
coin3d
alpacajs
package.json
drive
scriptella
tosca
gpio
pylons
fractions
inversion-of-control
sinch
corenlp-server
send
postback
cart
jmockit
papaparse
biztalk-rule-engine
pdw-file-browser
processwire
searchkit
docfx
modernizr
node-mssql
vmware-fusion
movilizer
show-hide
vaadin-charts
jide
opennms
term
jqchart
rackspace-cloud
gpg-signature
rsa-archer-grc
donations
slackware
preprocessor
dotnetnuke-7
eigenvector
deep
invoke-sqlcmd
toast
libvlc
sapi
qt5.2
avisynth
opserver
doctype
mod-proxy
sha512
canvg
nutiteq
bufferedinputstream
kubuntu
jquery-forms-plugin
osc
rrule
qtwebengine
apache-spark-1.3
beatsmusic
contrast
spy++
with-statement
ora-00904
tinyxml
ios8-extension
android-framework
websphere-esb
ice-cube
ebay-lms
mvc-editor-templates
route-provider
composite-component
panda3d
midlet
cakephp-1.2
josql
usertype
relative
role
workflow-services
pylucene
creole
inline-formset
squishit
timertask
isapi-extension
qtabbar
fail-fast-fail-early
movieplayer
wspbuilder
great-circle

Resources

Encrypt Message