You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<spanclass="notes">**Note:**`mbed test` does not work in applications that contain a `main` function that is outside of a `TESTS` directory.</span>
729
730
731
+
## Unit testing
732
+
733
+
Use the `mbed test --unittests` command to build and run unit tests, or to generate files for new unit tests.
734
+
735
+
Build and run unit tests with `mbed test --unittests`. The arguments are:
736
+
737
+
*`--compile` to only compile unit tests.
738
+
*`--run` to only run unit tests.
739
+
*`-c` or `--clean` to clean build directory.
740
+
*`--profile debug` to prepare debug build.
741
+
*`--coverage <TYPE>` to generate code coverage report where TYPE can be "html", "xml" or "both".
742
+
*`-m <NAME>` or `--make-program <NAME>` to select which make build tool to use where NAME can be "make", "gmake", "mingw32-make" or "ninja".
743
+
*`-g <NAME>` or `--generator <NAME>` to select which CMake generator to use where NAME can be "Unix Makefiles", "MinGW Makefiles" or "Ninja".
744
+
*`-r <EXPRESSION>` or `--regex <EXPRESSION>` to run tests matching the regular expression.
745
+
*`--build <PATH>` to specify build directory.
746
+
*`-v` or `--verbose` for verbose diagnostic output.
747
+
748
+
Generate files for a new unit test with `mbed test --unittests --new <FILE>`.
749
+
750
+
### Building and running unit tests
751
+
752
+
You can specify to only **build** the unit tests by using the `--compile option:
753
+
754
+
```
755
+
$ mbed test --unittests --compile
756
+
```
757
+
758
+
You can specify to only **run** the unit tests by using the `--run` option:
759
+
760
+
```
761
+
$ mbed test --unittests --run
762
+
```
763
+
764
+
If you do not specify any of these, `mbed test --unittests` will build all available unit tests and run them.
765
+
766
+
### Running a subset of tests
767
+
768
+
You can run a **limited set** of unit tests by using the `-r` or `--regex` option. This takes a regular expression, which it compares against the test names. For example to run all cellular unit tests you can specify:
769
+
770
+
```
771
+
$ mbed test --unittests -r cellular
772
+
```
773
+
774
+
### Getting code coverage
775
+
776
+
You can generate a code coverage report by using the `--coverage` option. For example to create an html report you can specify:
777
+
778
+
```
779
+
$ mbed test --unittests --coverage html
780
+
```
781
+
782
+
### Creating new unit tests
783
+
784
+
All unit tests are under `mbed-os/UNITTESTS` directory. You can **generate** the necessary files for a unit test by using the `--new` option. For example to create the files for `rtos/Semaphore.cpp` you can specify:
dict(name='--test-spec', dest="test_spec", help="Path used for the test spec file used when building and running tests (the default path is the build directory)"),
2620
2620
dict(name='--app-config', dest="app_config", help="Path of an application configuration file. Default is to look for \"mbed_app.json\""),
2621
2621
dict(name='--test-config', dest="test_config", help="Path or mbed OS keyword of a test configuration file. Example: ethernet, odin_wifi, or path/to/config.json"),
2622
+
dict(name='--coverage', choices=['html', 'xml', 'both'], help='Generate code coverage report for unit tetsts'),
2623
+
dict(name=['--make-program'], choices=['gmake', 'make', 'mingw32-make', 'ninja'], help='Which make program to use for unit tests'),
2624
+
dict(name=['--generator'], choices=['Unix Makefiles', 'MinGW Makefiles', 'Ninja'], help='Which CMake generator to use for unit tests'),
2625
+
dict(name='--new', help='generate files for a new unit test', metavar="FILEPATH"),
2626
+
dict(name=['-r', '--regex'], help='Run unit tests matching regular expression'),
2627
+
dict(name=['--unittests'], action="store_true", help='Run only unit tests'),
2622
2628
dict(name='--build-data', dest="build_data", default=None, help="Dump build_data to this file"),
0 commit comments