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
  • 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

Children
Related