J
Joe Van Dyk
Say I've written a class that wraps around a particular (complex)
communication service library.
I want to unit test objects that use that communication service.
Is the "best practice" to create a Communication_Service abstract base
class that my Concrete_Communication_Service and my
Mock_Communication_Service both inherit from? (and then use the mock
service when unit testing)
Or would I use templates somehow?
In Ruby, I'd create a mock communication class that just had the same
functions as the real communication class and, when testing, pass in the
mock communication object instead of the real communication object.
But, in C++, the mock and real object need to be of the same type, right?
Right now, I have
class Foo
{
Communication_Service* _communication;
public:
Foo(Communication_Service &comm) : _communication(&comm);
};
Then, in the test driver, I create Mock communication object and give
that to Foo's constructor. And in the real program, I create a real
communication object and give that to Foo's constructor.
(using unit testing when learning C++ is great, by the way. I can't
imagine doing it any other way.)
Thanks,
Joe
communication service library.
I want to unit test objects that use that communication service.
Is the "best practice" to create a Communication_Service abstract base
class that my Concrete_Communication_Service and my
Mock_Communication_Service both inherit from? (and then use the mock
service when unit testing)
Or would I use templates somehow?
In Ruby, I'd create a mock communication class that just had the same
functions as the real communication class and, when testing, pass in the
mock communication object instead of the real communication object.
But, in C++, the mock and real object need to be of the same type, right?
Right now, I have
class Foo
{
Communication_Service* _communication;
public:
Foo(Communication_Service &comm) : _communication(&comm);
};
Then, in the test driver, I create Mock communication object and give
that to Foo's constructor. And in the real program, I create a real
communication object and give that to Foo's constructor.
(using unit testing when learning C++ is great, by the way. I can't
imagine doing it any other way.)
Thanks,
Joe