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

Unity Test Framework - Adding multiple test files

Hello,

I am trying to integrate the Unity test framework into our project and running into issues with how to add additional test files.
Nordic provides one example project in the nRF Connect SDK repository here: https://github.com/nrfconnect/sdk-nrf/tree/master/tests/unity/example_test.

This sample was helpful but the moment I attempt to add another source file, "example_test_2.c" for example, the generation of the test binary fails.
It seems that I can only generate one test runner per CMake project with the CMake directive: "test_runner_generate(src/example_test.c)". 

Can Nordic provide any help or direction here?

Parents Reply Children
  • Hey ,

    I know it has been quite some time since my last update but I am still having troubles with this.

    Using the Unity test example located in the nRF Connect SDK here: https://github.com/nrfconnect/sdk-nrf/tree/master/tests/unity/example_test, if the developer wanted to add an additional file to the module, say src/uut/uut_2.c, and the developer wanted to test the functions in this file with the same test project how would the developer go about doing this?

    One way to do so would be to modify the CMakeLists.txt:

    # add module uut
    target_sources(app PRIVATE src/uut/uut.c)
    target_sources(app PRIVATE src/uut/uut_2.c) <-- add new source file here
    target_include_directories(app PRIVATE ./src/uut)

    and then add additional test functions inside example_test.c but that can get huge really fast, even though both source files are part of the same module it is still hard to organize.

    If you try to add example_test_2.c to the project to organize all tests for uut_2.c inside of, when you add "test_runner_generate(src/example_test_2.c)" to CMakeLists.txt you will get an error during compilation. This is due to the fact that, as you said previously, the script only accepts one file.

    In summary, even though I have nicely organized modules as part of my project, the Unity test project for the modules requires that you only have one test file for the entire module. This "test runner" file gets huge and does not allow for organization of specific files inside the module.

    Has anyone at Nordic ran into this and can provide a solution and/or workaround?

    Thanks,
    Cody

  • Hi Cody, 

    I got the following from the developer:

    so it's a limitation of unity, there is one runner for one test file generated. there can be multiple uut_2.c files attached to the project but only one test file. Imo, if there are too many tests for a single file there, I would try to split them logically into multiple test projects for the same module.

    -Amanda H.

  • Okay, just to confirm, every time I "split them out logically into multiple test projects" I am going to need a new CMakeLists.txt, Kconfig, and prj.conf for each test file to which CMake/Make is ran across and a new binary is generated?

    Looking at a Unity sample located at https://github.com/ThrowTheSwitch/Unity/tree/master/examples/example_1 it would be nice if I could organize in a similar fashion. I think the limitation might exist as part of the the nRF Connect SDK's Unity helper functions located in https://github.com/nrfconnect/sdk-nrf/blob/master/tests/unity/CMakeLists.txt and less so on Unity based on the example project.

    Thanks for your continued assistance,
    Cody

  • Hi Cody,

    Cody said:
    just to confirm, every time I "split them out logically into multiple test projects" I am going to need a new CMakeLists.txt, Kconfig, and prj.conf for each test file to which CMake/Make is ran across and a new binary is generated?

    Yes. 

    -Amanda H. 

Related