|
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 | There are two testing frameworks: Greentea and Icetea. Greentea provides tests designed for driver porting and target verification. Icetea provides and manages tests for multiple devices at the same time. For example, you can test the network setup for a server and multiple clients, simultaneously controlling them from the test environment.
|
@@ -210,6 +212,65 @@ As shown above, tests exist inside `TESTS\testgroup\testcase\` directories. Plea
|
210 | 212 |
|
211 | 213 | <span class="notes">**Note:** `mbed test` does not work in applications that contain a `main` function that is outside of a `TESTS` directory.</span>
|
212 | 214 |
|
| 215 | +### Unit testing |
| 216 | + |
| 217 | +Use the `mbed unittest` command to build and run unit tests, or to generate files for new unit tests. |
| 218 | + |
| 219 | +Build and run unit tests with `mbed unittest`. The arguments are: |
| 220 | + |
| 221 | +* `--compile` to only compile unit tests. |
| 222 | +* `--run` to only run unit tests. |
| 223 | +* `-c` or `--clean` to clean build directory. |
| 224 | +* `-d` or `--debug` to prepare debug build. |
| 225 | +* `--coverage <TYPE>` to generate code coverage report where TYPE can be "html", "xml" or "both". |
| 226 | +* `-m <NAME>` or `--make-program <NAME>` to select which make build tool to use where NAME can be "make", "gmake", "mingw32-make" or "ninja". |
| 227 | +* `-g <NAME>` or `--generator <NAME>` to select which CMake generator to use where NAME can be "Unix Makefiles", "MinGW Makefiles" or "Ninja". |
| 228 | +* `-r <EXPRESSION>` or `--regex <EXPRESSION>` to run tests matching the regular expression. |
| 229 | +* `--build <PATH>` to specify build directory. |
| 230 | +* `-v` or `--verbose` for verbose diagnostic output. |
| 231 | + |
| 232 | +Generate files for a new unit test with `mbed unittest --new <FILE>`. |
| 233 | + |
| 234 | +### Building and running unit tests |
| 235 | + |
| 236 | +You can specify to only **build** the unit tests by using the `--compile option: |
| 237 | + |
| 238 | +``` |
| 239 | +$ mbed unittest --compile |
| 240 | +``` |
| 241 | + |
| 242 | +You can specify to only **run** the unit tests by using the `--run` option: |
| 243 | + |
| 244 | +``` |
| 245 | +$ mbed unittest --run |
| 246 | +``` |
| 247 | + |
| 248 | +If you do not specify any of these, `mbed unittest` builds all available unit tests and runs them. |
| 249 | + |
| 250 | +### Running a subset of tests |
| 251 | + |
| 252 | +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: |
| 253 | + |
| 254 | +``` |
| 255 | +$ mbed unittest -r cellular |
| 256 | +``` |
| 257 | + |
| 258 | +### Getting code coverage |
| 259 | + |
| 260 | +You can generate a code coverage report by using the `--coverage` option. For example, to create an html report, you can specify: |
| 261 | + |
| 262 | +``` |
| 263 | +$ mbed unittest --coverage html |
| 264 | +``` |
| 265 | + |
| 266 | +### Creating new unit tests |
| 267 | + |
| 268 | +All unit tests are under the `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: |
| 269 | + |
| 270 | +``` |
| 271 | +$ mbed unittest --new rtos/Semaphore.cpp |
| 272 | +``` |
| 273 | + |
213 | 274 | ### Troubleshooting
|
214 | 275 |
|
215 | 276 | #### Import Mercurial (mbed.org) programs or libraries
|
|
0 commit comments