Issues Running Zephyr Unit Tests with twister on macOS

Hi everyone,
I’m working on running Zephyr unit tests using ztest and twister on macOS, and I'm running into issues where the tests are either not detected or fail to build depending on configuration.

Environment:

  • macOS (Apple Silicon / Intel)

  • nRF Connect SDK (NCS) version: v3.x

  • Zephyr version bundled with NCS

  • Using twister to run tests on native_posix

Test Directory Structure:

project_root/
  tests/
    my_module/
      src/
        test_my_module.c
      testcase.yaml

testcase.yaml

tests:
  my_module.unit:
    platform_allow: native_posix
    tags: unit

Issue #1: Tests Not Being Detected

When running: twister -T tests/my_module

I get: INFO - 0 test suites (0 configured, 0 executed, 0 skipped, 0 failed)

The test file is valid, includes <zephyr/ztest.h>, and compiles fine in isolation. It seems like Twister simply does not register the test suite.

What I Have Tried So Far:

  1. Verified that testcase.yaml exists and is in the correct directory.

  2. Ensured tests/ directory is under project root (not inside app/).

  3. Confirmed ztest is enabled and included.

  4. Tried specifying board/platform explicitly: twister -T tests/my_module -p native_posix

  5. Tried building manually with: west build -b native_posix (this works, so the toolchain appears functional)

Issue #2 (when detection succeeded once):

When I did get the test to be recognized after restructuring, the build failed due to:

  • Toolchain path mismatch on macOS

  • native_posix requiring additional host libraries
    (e.g., needing cmocka, glibc, or missing ninja on PATH depending on configuration)

So I’m not sure if:

  • The test structure is still incorrect for macOS builds

  • native_posix support on macOS requires extra dependencies or alternate execution strategy

  • Or if I should instead use unit_testing mode or native_sim rather than native_posix

Questions:

  1. Is there anything specific to macOS that affects how twister discovers or runs tests?

  2. Do I need to install additional dependencies for native_posix testing on macOS?

  3. Is there a recommended platform for running unit tests on macOS (for example, native_sim instead of native_posix)?

Any guidance or known macOS-specific steps would be very helpful.


Thanks in advance!

Parents Reply Children
Related