Search code examples
c++unit-testinggoogletest

Use gtest to write unit tests for a dynamic library


I am new to gtest and gmock but certainly finding it useful. Currently I have built gtest and wrote sample test cases and executed them to see a proper workflow of gtest.

As in my main usecase the library I want to unit test is a dll (dynamic linking library). Until now I have created the project as static library and and wrote unit test cases for the same and it works fine but when I build it as dll, visual studio gives me linker error while trying to find Calculator.lib. Shouldn't it find Calculator.dll in this case.

Why it is going to find the .lib ?I wonder how can I load dll to write unit test cases for ?

I am new to it, please pardon me for stupid question.


Solution

  • Pulling together the comments,

    export symbols

    when you make the dll.

    When you build the dll you will also get a lib file.

    Then as you can use Linker->Input->Additional Dependencies and add the name of the .lib file.

    This will pick up the exported symbols: make sure you actually export things to use them.