Running and creating unit test for nordic application

Hello. 

I am trying to learn how to implement unit tests for embedded c-application. I created simple example about my problem and I am having hard time actually running the tests using native sim or nrf9160dk as target. I am following these instructions from nordic: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/test_and_optimize/testing_unity_cmock.html 

I have installed these tools: Cmock,Unity & Ruby.

Everytime I try to run this command 'west build -b native_posix -t run', I get this output: 

```

PS C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test> west build -b native_posix -t run
usage: west [-h] [-z ZEPHYR_BASE] [-v] [-V] <command> ...
west: error: argument <command>: invalid choice: 'build' (choose from 'init', 'update', 'list', 'manifest', 'diff', 'status', 'forall', 'help', 'config', 'topdir', 'selfupdate')

```

I am using nrf connect from vscode.

0160.Unit.zip

  • Hello,

    Where are you running this command from? That is an error that appears when your environmental variables are set incorrectly.

    If your SDK version is set corrently in VS Code, then please try to open a new terminal of type "nRF Connect" and it should set up the environmental variables accordingly.

    You can also modify your ZEPHYR_BASE environmental variable manually to point to the path of the "zephyr" folder in NCS.

    Best regards,

    Michal

  • Hello,
    Thanks for the reply. I was originally  running the command from powershell.
    Now I switched to nrf Connect and got this error: 

    ´´´

    PS C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test> west build -b native_posix -t run
    -- west build: running target run
    ninja: error: loading 'build.ninja': No such file or directory .

    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\v2.3.0\opt\bin\cmake.EXE' --build 'C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test\build' --target run

    ´´´

    This looks like Cmake error. I am complete beginner when it comes to cmake, any suggestions what my cmakelist.txt file is missing?

    My SDK version is 2.3

    0640.Unit.zip

    I made slight changes:
    added Cmakelistst.txt to test directory
    created src folder and moved unity and tests module files there.

    Thanks in advance.

  • Could you try adding the -v (verbose) option to your build and show me what happens?

    Best regards,

    Michal

  • Running command with -v gives this output:

    ´´´

    PS C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test> west -v build -b native_posix -t run
    ZEPHYR_BASE=c:\ncs\v2.3.0\zephyr (origin: env)
    -- west build: running target run
    cmake version 3.20.5 is OK; minimum version is 3.13.1
    Running CMake: 'C:\ncs\toolchains\v2.3.0\opt\bin\cmake.EXE' --build 'C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test\build' --target run -- -v
    ninja: error: loading 'build.ninja': No such file or directory

    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\v2.3.0\opt\bin\cmake.EXE' --build 'C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test\build' --target run -- -v

    ´´´

  • Hi Arttu 

    Michal is on vacation so I will be handling the case while he is away. 

    Just so I can be sure that your build system is up an running and that we start with a known working sample. Could you open the sample found in ncs/ncs_versionnrf\/ests/unity/example_test and try to build the example_test? 

    use native_posix  as build target and if it fails post the build log

    Regards

    Runar

Related