Skip to content

Commit 673a07a

Browse files
committed
Incorporated the review comments
1 parent 75916c2 commit 673a07a

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

docs/debugging-testing/testing/unit_testing.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ Please install the following dependencies to use Mbed OS unit testing.
1212

1313
- GNU toolchains.
1414
- GCC 6 or later. We recommend you use MinGW-W64 on Windows, but any Windows port of the above GCC versions works.
15-
- CMake 3.0 or newer.
15+
- CMake 3.19.0 or newer.
1616
- Python 2.7.x, 3.5 or newer.
1717
- Pip 10.0 or newer.
1818
- Gcovr 4.1 or newer.
19-
- Mbed CLI 1.8.0 or newer.
2019

2120
Detailed instructions for supported operating systems are below.
2221

@@ -30,7 +29,7 @@ Detailed instructions for supported operating systems are below.
3029
sudo easy_install pip
3130
```
3231

33-
1. Install Gcovr and [Mbed CLI](../build-tools/mbed-cli-1.html) with `pip install "gcovr>=4.1" mbed-cli`.
32+
1. Install Gcovr `pip install "gcovr>=4.1"`.
3433

3534
### Installing dependencies on macOS
3635

@@ -46,7 +45,7 @@ In a terminal window:
4645
sudo easy_install pip
4746
```
4847

49-
1. Install Gcovr and [Mbed CLI](../build-tools/mbed-cli-1.html) with `pip install "gcovr>=4.1" mbed-cli`.
48+
1. Install Gcovr `pip install "gcovr>=4.1"`.
5049
1. (Optional) Install GCC with `brew install gcc`.
5150

5251
### Installing dependencies on Windows
@@ -57,17 +56,17 @@ In a terminal window:
5756
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
5857
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
5958
1. Add MinGW, CMake and Python into system PATH.
60-
1. Install Gcovr and [Mbed CLI](../build-tools/mbed-cli-1.html) with `pip install "gcovr>=4.1" mbed-cli`.
59+
1. Install Gcovr `pip install "gcovr>=4.1"`.
6160

6261
## Test code structure
6362

6463
Unit tests in the Mbed OS repository are located in the `UNITTESTS` directory of each library. We recommend unit test files use an identical directory path as the file under test. This makes it easier to find unit tests for a particular class or a module. For example, if the file you're testing is `some/example/path/ClassName.cpp`, then all the test files are in the `UNITTESTS/some/example/path/ClassName` directory. Each test suite needs to have its own `CMakeLists.txt` file for test CMake configuration.
6564

66-
All the stub sources are built in stub CMake library targets (e.g `mbed-stubs-rtos`) and linked to the `mbed-stubs` CMake target. The CMake target of the library unit under test is expected to link with the required stub libraries or `mbed-stubs` depending on the test case.
65+
All the stub sources are built in stub CMake library targets (e.g `mbed-stubs-rtos`) and linked to the `mbed-stubs` CMake target. The CMake target of the library unit under test is expected to link with the required stub libraries or `mbed-stubs` in case of requiring multiple stub libraries.
6766

68-
The new stub file should follow the naming convention `ClassName_stub.cpp` for the source file and `ClassName_stub.h` for the header file. They should be added under their respective existing stub CMake library or create their stubs library depends on their test cases.
67+
The new stub file should follow the naming convention `ClassName_stub.cpp` for the source file and `ClassName_stub.h` for the header file. They should be added under their respective existing stub CMake library or create their stub library in case of this `ClassName_stub` providing an implementation for an external source that is not part of the Mbed OS source.
6968

70-
All the Mbed OS header files are built with CMake `INTERFACE` libraries (e.g`mbed-headers-platform`). Stubbed header files reside in the `UNITTESTS/target_h` and are built with the `mbed-headers-base` CMake library. All CMake libraries containing header files are linked with `mbed-headers`. The CMake target of the library unit under test is expected to link with the required header file libraries or `mbed-headers` depending on the test case.
69+
All the Mbed OS header files are built with CMake `INTERFACE` libraries (e.g`mbed-headers-platform`). Stubbed header files reside in the `UNITTESTS/target_h` and are built with the `mbed-headers-base` CMake library. All CMake libraries containing header files are linked with `mbed-headers`. The CMake target of the library unit under test is expected to link with the required header file libraries or `mbed-headers` in case of requiring multiple header libraries.
7170

7271
All the stub libraries and header libraries are defined under `UNITTESTS/stubs/` directory.
7372

@@ -79,10 +78,6 @@ Registering unit tests to run happens automatically, and the test runner handles
7978

8079
For the build system to build a unit test, pass the `ON` or `OFF` value to `MBED_BUILD_UNITTESTS` in the command-line to include all the unit test suite directories into the build.
8180

82-
## Unit testing with Mbed CLI
83-
84-
Mbed CLI supports unit tests through the `mbed test --unittests` command. To learn how to use unit tests with Mbed CLI, please see the [unit testing documentation section](../build-tools/test-and-debug.html). For other information on using Mbed CLI, please see the [CLI documentation in handbook](../build-tools/mbed-cli.html).
85-
8681
### Writing unit tests
8782

8883
A unit tests suite consists of one or more test cases. The test cases should cover all the functions in a class under test. All the external dependencies are stubbed including the other classes in the same module. Avoid stubbing header files. Finally, analyze code coverage to ensure all code is tested, and no dead code is found.
@@ -135,7 +130,7 @@ With the following steps, you can write a unit test. This example creates dummy
135130
)
136131
```
137132
138-
1. Update the newly created `mbed-headers-example` library into exising target link library of `mbed-headers`.
133+
1. Add the newly created `mbed-headers-example` library into exising target link library of `mbed-headers`.
139134
140135
1. Create the following dummy classes source in `mbed-os/example/source`:
141136
@@ -218,20 +213,27 @@ This example does not use any Mbed OS code. If your unit tests do, remember to u
218213
219214
### Building and running unit tests
220215
221-
Use Mbed CLI to build and run unit tests. For advanced use, you can run CMake and a Make program directly.
216+
#### Mbed CLI 1
217+
218+
- Install [Mbed CLI 1](../build-tools/mbed-cli-1.html) with `pip install mbed-cli` command in Debian or Ubuntu or macOS or Windows and make sure that installed Mbed CLI 1 version 1.8.0 or newer.
219+
220+
- Mbed CLI 1 supports unit tests through the `mbed test --unittests` command. To learn how to use unit tests with Mbed CLI 1, please see the [unit testing documentation section](../build-tools/test-and-debug.html). For other information on using Mbed CLI 1, please see the [CLI documentation in handbook](../build-tools/mbed-cli-1.html).
221+
222+
#### Mbed CLI 2
223+
224+
- Mbed CLI 2 is not supporting the `mbed test --unittests` command, please use CMake and a Make command directly.
222225
223226
#### Build tests directly with CMake
224227
225228
1. Create a build directory: `mkdir UNITTESTS/build`.
226229
1. Move to the build directory: `cd UNITTESTS/build`.
227-
1. Run CMake using a relative path to the `UNITTESTS` folder as the argument. So from `UNITTESTS/build` use `cmake .. -DMBED_BUILD_UNITTESTS=ON`:
230+
1. Run CMake using a relative path to the `UNITTESTS` folder as the argument. So from `UNITTESTS/build` use `cmake ..-DMBED_BUILD_UNITTESTS=ON`:
228231
- Add `-g [generator]` if generating files other than Unix Makefiles. For example, for MinGW, use `-g "MinGW Makefiles"`.
229-
- Add `-DCMAKE_MAKE_PROGRAM=<value>`, `-DCMAKE_CXX_COMPILER=<value>` and `-DCMAKE_C_COMPILER=<value>` to use a specific Make program and compilers.
232+
- Add `-DCMAKE_MAKE_PROGRAM=<value>`, `-DCMAKE_CXX_COMPILER=<value>` and `-DCMAKE_C_COMPILER=<value>` to use a specific Make programand compilers.
230233
- Add `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
231234
- Add `-DCOVERAGE=True` to add coverage compiler flags.
232235
- Add `-Dgtest_disable_pthreads=ON` to run in a single thread.
233236
- See the [CMake manual](https://cmake.org/cmake/help/v3.0/manual/cmake.1.html) for more information.
234-
235237
1. Run a Make program to build tests.
236238
237239
#### Run tests directly with CTest

0 commit comments

Comments
 (0)