Reputation: 7554
I am starting to work in test driven C development.
I used CMock to generate my mock classes by running commands like:
ruby cmock.rb ../../../src/util.h
My current package structure is:
app/root
| bin
| *.*
| build
| *.*
|- cmake
|- modules
|- CodeCoverage.cmake
|- coverage
|- *.*
|- external
|- Unity
|- CMock
|- CMakeLists.txt
|- src
|- *.c
|- *.h
|- CMakeLists.txt
|- mocks
|- *.c
|- *.h
|- CMakeLists.txt
|- tests
|- *.c
|- *.h
|- CMakeLists.txt
|- CMakeLists.txt
I have the CMakeLists.txt setup to compile src as a library:
add_library(app SHARED ${SOURCE_FILES})
Tests is setup to compile as an executable:
add_executable(tests ${TEST_SOURCES})
target_link_libraries(tests app Unity mocks)
And mocks is setup to compile as a library:
add_library(mocks ${MOCK_SOURCES})
target_link_libraries(mocks app Unity CMock)
I've tried multiple locations for the mock headers and have been playing around, but I'm missing a fundamental of how to not get a multiple definitions error.
Can anyone lend some guidance on what is incorrect about my file structure or strategy?
Upvotes: 0
Views: 2604
Reputation: 61
See the answer here: https://github.com/ThrowTheSwitch/CMock/issues/97
Basically, it all comes down to linking just the files that you need for each test. When using Unity, every test becomes its own Executable.
Upvotes: 2