Skip to content

Document Unit Testing #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/tools/offline/cli-test-debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ As shown above, tests exist inside `TESTS\testgroup\testcase\` directories. Plea

### Unit testing

Use the `mbed unittest` command to build and run unit tests, or to generate files for new unit tests.
Use the `mbed test --unittests` command to build and run unit tests, or to generate files for new unit tests.

Build and run unit tests with `mbed unittest`. The arguments are:
Build and run unit tests with `mbed test --unittests`. The arguments are:

* `--compile` to only compile unit tests.
* `--run` to only run unit tests.
Expand All @@ -229,46 +229,46 @@ Build and run unit tests with `mbed unittest`. The arguments are:
* `--build <PATH>` to specify build directory.
* `-v` or `--verbose` for verbose diagnostic output.

Generate files for a new unit test with `mbed unittest --new <FILE>`.
Generate files for a new unit test with `mbed test --unittests --new <FILE>`.

### Building and running unit tests

You can specify to only **build** the unit tests by using the `--compile option:

```
$ mbed unittest --compile
$ mbed test --unittests --compile
```

You can specify to only **run** the unit tests by using the `--run` option:

```
$ mbed unittest --run
$ mbed test --unittests --run
```

If you do not specify any of these, `mbed unittest` builds all available unit tests and runs them.
If you do not specify any of these, `mbed test --unittests` builds all available unit tests and runs them.

### Running a subset of tests

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:

```
$ mbed unittest -r cellular
$ mbed test --unittests -r cellular
```

### Getting code coverage

You can generate a code coverage report by using the `--coverage` option. For example, to create an html report, you can specify:

```
$ mbed unittest --coverage html
$ mbed test --unittests --coverage html
```

### Creating new unit tests

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:

```
$ mbed unittest --new rtos/Semaphore.cpp
$ mbed test --unittests --new rtos/Semaphore.cpp
```

### Troubleshooting
Expand Down