views:

346

answers:

3

Hi,

I am trying to set up some unit tests for an existing c++ project.

Here's the setup: I have chosen Google Mock, which includes Google Test. I have added another project (called Tests) to the Visual Studio Solution. The units to test are in another project called Main. The plan is to add each cpp file that I want to test to the Tests project. The Tests project has access to all header files from Main.

I have added one cpp file to the Tests project, and it compiles, but comes up with linker errors. Most are because of a class derived from COleDateTime, called CTimeValue. The unit under test has methods with pass-by-value CTimeValue parameters and also declares some CTimeValue attributes.

I want to test the UUT in isolation, and use mocks and fakes for all dependencies. I don't see how to do it with CTimeValue. It is used as a value, contains no virtual methods, but is still quite complex and would deserve a seperate unit test.

CTimeValue is only one of many classes that is like this in the project. How can I isolate the testing of classes that use these user-defined types?

Cheers, Felix

+2  A: 

Sometimes one can not simply mock things. In that case what you can do is have a comprehensive test for the class in question (CTimeValue) and make sure you run the tests for that class as a subsuite in your other test.

lothar
This will have to do, thanks for the answer. Mocks don't seem to work well with value semantics.
TheFogger
A: 

Using a mock object you only need to add the method signatures that your UUT uses so maybe you can create a mock using google mock. Of course you will need a separate test suite for the CTimeValue class, and if you have that then it is probably better to link in the actual object. You need to decide if it is worth the effort to create an interface class to create the mock from.

mikelong
A: 

Mocks are most suitable for working with objects that provide services for each other, the expectations on the mocks describe their relationships. There's not much point in mocking value objects.

Steve Freeman