Unit testing c++ NCS code

Hi,

Im currently using Cmock and Unity like described here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/test_and_optimize/testing_unity_cmock.html

the difference is that my usercode is written in c++, which means that I will need to instantiate classes and use strings, vectors etc. in my tests.

I got everything working up until the point where I get undefined reference to `test_suiteTearDown(int)'. when I wrap my code in extern "C"{...} I will get undefined reference to `unity_main'. I think this is due to the unity functions now being compiled with c++ linkage.

this seems to be just a tiny thing that stops me from using this setup for c++ testing but I dont know how to solve it. Any ideas?

I also tried to use Ztest with Cmock instead, but this doesnt work because NCS cmock implementation seems to depend on unity.

I would love if anyone could share some ideas on how to solve this problem.

Kind regards,

Jonas

Parents Reply
  • #include <unity.h>
    //#include "../../../SerialHandler.h"
    
    
    
    void test_unityexample()
    {
    
        TEST_ASSERT_EQUAL(1,1);
    }
    
    /* It is required to be added to each test. That is because unity's
     * main may return nonzero, while zephyr's main currently must
     * return 0 in all cases (other values are reserved).
     */
    extern void test_cpptest(void);
    extern int unity_main(void);
    
    int main(void)
    {
    	(void)unity_main();
    
    	return 0;
    }
    

    this is the unitytest.cpp

Children
Related