|
1 | 1 | ## Test and debug
|
2 | 2 |
|
| 3 | +### Testing |
| 4 | + |
3 | 5 | Use the `mbed test` command to compile and run tests.
|
4 | 6 |
|
5 | 7 | The arguments to `test` are:
|
@@ -158,6 +160,65 @@ As shown above, tests exist inside `TESTS\testgroup\testcase\` directories. Plea
|
158 | 160 |
|
159 | 161 | <span class="notes">**Note:** `mbed test` does not work in applications that contain a `main` function that is outside of a `TESTS` directory.</span>
|
160 | 162 |
|
| 163 | +### Unit testing |
| 164 | + |
| 165 | +Use the `mbed unittest` command to build and run unit tests, or to generate files for new unit tests. |
| 166 | + |
| 167 | +Build and run unit tests with `mbed unittest`. The arguments are: |
| 168 | + |
| 169 | +* `--compile` to only compile unit tests. |
| 170 | +* `--run` to only run unit tests. |
| 171 | +* `-c` or `--clean` to clean build directory. |
| 172 | +* `-d` or `--debug` to prepare debug build. |
| 173 | +* `--coverage <TYPE>` to generate code coverage report where TYPE can be "html", "xml" or "both". |
| 174 | +* `-m <NAME>` or `--make-program <NAME>` to select which make build tool to use where NAME can be "make", "gmake", "mingw32-make" or "ninja". |
| 175 | +* `-g <NAME>` or `--generator <NAME>` to select which CMake generator to use where NAME can be "Unix Makefiles", "MinGW Makefiles" or "Ninja". |
| 176 | +* `-r <EXPRESSION>` or `--regex <EXPRESSION>` to run tests matching the regular expression. |
| 177 | +* `--build <PATH>` to specify build directory. |
| 178 | +* `-v` or `--verbose` for verbose diagnostic output. |
| 179 | + |
| 180 | +Generate files for a new unit test with `mbed unittest --new <FILE>`. |
| 181 | + |
| 182 | +### Building and running unit tests |
| 183 | + |
| 184 | +You can specify to only **build** the unit tests by using the `--compile option: |
| 185 | + |
| 186 | +``` |
| 187 | +$ mbed unittest --compile |
| 188 | +``` |
| 189 | + |
| 190 | +You can specify to only **run** the unit tests by using the `--run` option: |
| 191 | + |
| 192 | +``` |
| 193 | +$ mbed unittest --run |
| 194 | +``` |
| 195 | + |
| 196 | +If you do not specify any of these, `mbed unittest` will build all available unit tests and run them. |
| 197 | + |
| 198 | +### Running a subset of tests |
| 199 | + |
| 200 | +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: |
| 201 | + |
| 202 | +``` |
| 203 | +$ mbed unittest -r cellular |
| 204 | +``` |
| 205 | + |
| 206 | +### Getting code coverage |
| 207 | + |
| 208 | +You can generate a code coverage report by using the `--coverage` option. For example to create an html report you can specify: |
| 209 | + |
| 210 | +``` |
| 211 | +$ mbed unittest --coverage html |
| 212 | +``` |
| 213 | + |
| 214 | +### Creating new unit tests |
| 215 | + |
| 216 | +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: |
| 217 | + |
| 218 | +``` |
| 219 | +$ mbed unittest --new rtos/Semaphore.cpp |
| 220 | +``` |
| 221 | + |
161 | 222 | ### Troubleshooting
|
162 | 223 |
|
163 | 224 | #### Unable to import Mercurial (mbed.org) programs or libraries.
|
|
0 commit comments