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
twisterto run tests onnative_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:
-
Verified that
testcase.yamlexists and is in the correct directory. -
Ensured
tests/directory is under project root (not insideapp/). -
Confirmed
ztestis enabled and included. -
Tried specifying board/platform explicitly: twister -T tests/my_module -p native_posix
-
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_posixrequiring additional host libraries
(e.g., needingcmocka,glibc, or missingninjaon PATH depending on configuration)
So I’m not sure if:
-
The test structure is still incorrect for macOS builds
-
native_posixsupport on macOS requires extra dependencies or alternate execution strategy -
Or if I should instead use
unit_testingmode ornative_simrather thannative_posix
Questions:
-
Is there anything specific to macOS that affects how
twisterdiscovers or runs tests? -
Do I need to install additional dependencies for
native_posixtesting on macOS? -
Is there a recommended platform for running unit tests on macOS (for example,
native_siminstead ofnative_posix)?
Any guidance or known macOS-specific steps would be very helpful.
Thanks in advance!
