Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Is it possible to run tests against lib binary #69

Closed
novocodev opened this issue Mar 9, 2016 · 2 comments
Closed

Is it possible to run tests against lib binary #69

novocodev opened this issue Mar 9, 2016 · 2 comments

Comments

@novocodev
Copy link

I have a project that uses polly to build a library for iOS and OSX, I have added unit tests via ctest which executes a class that uses GTest

I have one question, I have to add all the library source files to the runUnitTest exe definition.

e.g. I have added the following to my to level CMakeLists.txt

# Unit Tests

if(IOS)
    add_test(
            NAME SimpleTest COMMAND "${CMAKE_COMMAND}" -E echo "iOS testing ignored"
    )
else()
    add_executable(runUnitTests foo_unit_tests.cpp ${LIB_SOURCE_FILES} )
    target_link_libraries(runUnitTests PUBLIC GTest::main)

    enable_testing()

    add_test(NAME SimpleTest COMMAND runUnitTests)
endif()

Is there a way force the library to build and link to it rather than pull in all the library source to the unit tests?

My library is defined as

add_library(foo SHARED ${LIB_SOURCE_FILES})

I hoped it would build and link to the tests if I added:

target_link_libraries(runUnitTests PUBLIC foo)

But that caused the linker to fail when trying to find the foo library symbols used in the tests.

@novocodev
Copy link
Author

For Unit Tests accessing private library functions makes sense so pulling in the lib source is maybe not so bad.

I would still be interested to know if there are alternatives to just adding the lib source to the unit test executable.

@ruslo
Copy link
Owner

ruslo commented Mar 10, 2016

I have a project that uses polly to build a library for iOS and OSX

So in fact we are talking about OSX only according to the configuration I see.

But that caused the linker to fail when trying to find the foo library symbols used in the tests

That is something strange. This is a usual way to work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants