P.S. Apologies, I’m relatively new into testing and C++, so forgive me for any obvious mistakes.
Let’s say I have these files (Please disregard the lack of header files here.)
A.hpp
namespace A {
namespace upper {
void func1();
}
}
B.hpp
namespace B {
namespace lower {
void func2();
}
}
A.cpp
namespace A {
namespace upper {
void func1() {
B::lower::func2();
}
}
}
B.cpp
namespace B {
namespace lower {
void func2() {
cout << Actual B called;
}
}
}
Now, normally calling A::upper::func1() should display “Actual B called”. However I do not want to call the Actual B, I want to be able to mock it. At this point the source code cannot change without significant refactoring. Is there a way to mock out this call using GMock?
I tried overriding B
Test.cpp
namespace B {
namespace lower {
void func2() {
cout << Mock B called;
}
}
}
int main() {
B::lower::func2();
}
I am getting these errors
Error LNK2005 “void __cdecl B::lower::func2(void)” (?lower@0B@@YAXXZ) already defined in B.obj TestOverrideForMock 1
Error LNK1169 one or more multiply defined symbols found TestOverrideForMock 1
Poseidon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1