This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unit testing and mocking in NRF Connect SDK

Hi, I am trying to add some unit testing in my NRF Connect SDK based project. I am using Unity + CMock suggested here. For files with no complicated dependencies it works fine but I have problems with mocking BLE related headers.

Assume I have file fileA.c in my zephyr project source directory I want to test, which handles BLE initialization, and tracks connection/disconnection events. It includes header:

#include <bluetooth/gatt.h>

Next, I have file fileB.c with tests in another directory, in separate zephyr project set up to test file A.

When I try to mock given header with:

cmock_handle($ENV{ZEPHYR_BASE}/include/bluetooth/gatt.h bluetooth)
and build it I have two types of error
1. Compiler complains about not defined macros like ‘CONFIG_BT_MAX_CONN’, ‘BT_GATT_CCC_MAX’ etc.. This I could resolve it by adding "CONFIG_BT=y" (and other commands related to my BT zephyr configuration) to tests prj.conf file. Is this correct approach?
2. Compiler complains about "struct bt_conn", there is similar error for every function in gatt.h that uses this struct:
mocks/bluetooth/mock_gatt.c:3061:113: error: invalid application of ‘sizeof’ to incomplete type ‘struct bt_conn’
This I could not overcome
Also, when I add manually some dummy struct definition for bt_conn in mock_gatt.h after it is generated (of course it is not fix for my problem) it compiles but when I run the tests there is error:
Error: Bluetooth device missing. Specify one using --bt-dev=hciN
This could be another issue after dealing with first two...
Hope you could help me out
Parents Reply Children
No Data
Related