Question

I want to write unit tests using Google Test / Mock for code in my DLL. The test code is supposed to be compiled into my DLL.

I read in the Google Test Primer that this is possible, but that gtest has to be compiled into a DLL then (and I guess the same thing holds for gmock, too).

Has anybody compiled and used the framework as DLL's and can tell me the most important project settings (I use VS2010) and how to use the resulting DLL's to run the tests?

Was it helpful?

Solution

GoogleTest and GoogleMock do not need to be compiled into a .dll.

Rather it is saying that they need to be compiled with the same Runtime Library setting as the project consuming (linking) them (/MD or /MT). Runtime Library Settings

Consistency is the key! When linking any library (LIB or DLL), they should have the same Runtime Library setting as the project (or vice versa).

Runtime Library Options

I would also recommend using the same Character Set setting.

OTHER TIPS

Set preprocessor flag (properties->c/c++->Preprocessor->Preprocessor Definitions) GTEST_CREATE_SHARED_LIBRARY to build the Gmock as dll, and build the dll that consumes gmock with GTEST_LINKED_AS_SHARED_LIBRARY

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top