Mocking IDF components with Unity & CMock
Posted: Thu Mar 25, 2021 9:09 pm
I'm attempting to mock hardware-dependent IDF components so I can implement unit testing. I'm using IDF v4.3, which has cmock as a component.
I've managed to generate cmock mocks for the driver/touch_sensor.h header file, using the CMakeLists.txt in the spi_flash component for reference. When I include functions from my code under test (that contain #include "driver/touch_sensor.h") in my test cases, I find I get multiple definition errors. This is due to both the presence of original component function definitions, and the mocked versions being present in the executable.
Is there a way of compiling this test, but excluding only the original component that is being mocked, in order to avoid these errors?
Thanks!
I've managed to generate cmock mocks for the driver/touch_sensor.h header file, using the CMakeLists.txt in the spi_flash component for reference. When I include functions from my code under test (that contain #include "driver/touch_sensor.h") in my test cases, I find I get multiple definition errors. This is due to both the presence of original component function definitions, and the mocked versions being present in the executable.
Is there a way of compiling this test, but excluding only the original component that is being mocked, in order to avoid these errors?
Thanks!