E
earthwormgaz
Hello,
I'm after doing some C++ unit testing, I'm using CppUnit. I like the
look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no
good to me sadly.
So, I have class A, and it uses classes B and C. B and C have methods
A uses, but they're not virtual, and I don't want to hack the code so
that they are just to allow Unit Tests to work. This means that
inheriting from B and C to provide Mock classes is a non starter.
So, I've been trying to provide a mock implementation which is
basically a copy of B or C, but with the guts ripped out and swapped
for mock code. I've then tried to get the code for A, which is under
test, to include the mock versions of the classes headers it depends
on, and link to the objects built from the mock source.
The trouble is, A, B and C are all in the same directory. So, when A
does #include "B.h", it picks up the real version, even if I add the
include path to the mock header. That's because the current directory
takes precedence using VC++, it may well do with GCC and Suncc, which
I'm also using.
I've tried to get around this by not building an object file for class
A, but using A.obj which has already been built, but linking it
against my mock versions of B.obj and C.obj. This would work, except
that C.h defines C::~C(), and so A.obj ends up with a definition of
C::~C() in it, and I get multiply defined symbol link errors. I could
make sure all method definitions are in cpp files, but often having a
getter or setter inline is perfectly sensible.
How do people get around these issues of mocking out classes
effectively from a build system point of view?
I'm after doing some C++ unit testing, I'm using CppUnit. I like the
look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no
good to me sadly.
So, I have class A, and it uses classes B and C. B and C have methods
A uses, but they're not virtual, and I don't want to hack the code so
that they are just to allow Unit Tests to work. This means that
inheriting from B and C to provide Mock classes is a non starter.
So, I've been trying to provide a mock implementation which is
basically a copy of B or C, but with the guts ripped out and swapped
for mock code. I've then tried to get the code for A, which is under
test, to include the mock versions of the classes headers it depends
on, and link to the objects built from the mock source.
The trouble is, A, B and C are all in the same directory. So, when A
does #include "B.h", it picks up the real version, even if I add the
include path to the mock header. That's because the current directory
takes precedence using VC++, it may well do with GCC and Suncc, which
I'm also using.
I've tried to get around this by not building an object file for class
A, but using A.obj which has already been built, but linking it
against my mock versions of B.obj and C.obj. This would work, except
that C.h defines C::~C(), and so A.obj ends up with a definition of
C::~C() in it, and I get multiply defined symbol link errors. I could
make sure all method definitions are in cpp files, but often having a
getter or setter inline is perfectly sensible.
How do people get around these issues of mocking out classes
effectively from a build system point of view?