@@ -360,7 +360,16 @@ efforts into the specific module in question. This will speed up testing since
360
360
only the module will have to be compiled in, and the tested functions will be
361
361
called directly.
362
362
363
- Examples of unit tests can be found in the :zephyr_file: `tests/unit/ ` folder.
363
+ To setup unit tests you have to add a CMakeLists.txt, a testcases.yml and a
364
+ prj.conf to the directory containing the unit test source files. The resulting
365
+ binary from this directory is build with the -DBOARD=unit_testing. When twister
366
+ is invoked the script zephyr/scripts/pylib/twister/twisterlib/testplan.py
367
+ filters out all testcases.yml in which type: unit is not set. Only unit tests
368
+ are executed with a firmware build with BOARD=unit_testing.
369
+
370
+ CMakeLists.txt
371
+ ==============
372
+
364
373
In order to declare the unit tests present in a source folder, you need to add
365
374
the relevant source files to the ``testbinary `` target from the CMake
366
375
:zephyr_file: `unittest <cmake/modules/unittest.cmake> ` component. See a minimal
@@ -383,6 +392,41 @@ and are used to decide whether a test failed or passed by verifying whether an
383
392
interaction with an object occurred, and if required, to assert the order of
384
393
that interaction.
385
394
395
+ testcases.yaml
396
+ ==============
397
+
398
+ You have to set the value for the key "type" to "unit" in the testcase.yaml
399
+
400
+ .. code-block :: yaml
401
+
402
+ tests :
403
+ testscenario.testsuite :
404
+ tags : your_tag
405
+ type : unit
406
+
407
+ prj.conf
408
+ ========
409
+
410
+ For unit tests this contains usually only
411
+
412
+ .. code-block :: kconfig
413
+
414
+ CONFIG_ZTEST=y
415
+
416
+ If your unit tests require additional libraries (e.g. math-lib) you will have to
417
+ add them either via the CMakeLists.txt or in the testcase.yaml:
418
+
419
+ .. code-block :: yaml
420
+
421
+ tests :
422
+ testscenario.testsuite :
423
+ tags : your_tag
424
+ type : unit
425
+ extra_args :
426
+ - EXTRA_LDFLAGS="-lm"
427
+
428
+ Examples of unit tests can be found in the :zephyr_file: `tests/unit/ ` folder.
429
+
386
430
Best practices for declaring the test suite
387
431
*******************************************
388
432
0 commit comments