Skip to content

Commit a6df2a0

Browse files
rajkan01hugueskamba0xc0170
authored
Apply suggestions from code review
Co-authored-by: Hugues Kamba-Mpiana <[email protected]> Co-authored-by: Martin Kojtal <[email protected]>
1 parent 45284f1 commit a6df2a0

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

docs/debugging-testing/testing/unit_testing.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ Detailed instructions for supported operating systems are below.
2929
sudo easy_install pip
3030
```
3131

32-
1. Install Gcovr `pip install "gcovr>=4.1"`.
32+
### Installing dependencies on Debian or Ubuntu
33+
1. Install the compilation packages to the host:
34+
``
35+
sudo apt-get -y install build-essential cmake
36+
``
37+
1. Install Python and its package manager:
38+
``
39+
sudo apt-get -y install python python-setuptools && sudo easy_install pip
40+
``
41+
1. Install the addition Python package `gcovr` for code coverage report:
42+
``
43+
pip install "gcovr>=4.1"
44+
``
3345

3446
### Installing dependencies on macOS
3547

@@ -45,7 +57,10 @@ In a terminal window:
4557
sudo easy_install pip
4658
```
4759

48-
1. Install Gcovr `pip install "gcovr>=4.1"`.
60+
1. Install the addition Python package `gcovr` for code coverage report:
61+
``
62+
pip install "gcovr>=4.1"
63+
``
4964
1. (Optional) Install GCC with `brew install gcc`.
5065

5166
### Installing dependencies on Windows
@@ -56,15 +71,18 @@ In a terminal window:
5671
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
5772
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
5873
1. Add MinGW, CMake and Python into system PATH.
59-
1. Install Gcovr `pip install "gcovr>=4.1"`.
74+
1. Install the addition Python package `gcovr` for code coverage report:
75+
``
76+
pip install "gcovr>=4.1"
77+
``
6078

6179
## Test code structure
6280

63-
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.
81+
Unit tests are located in the `tests/UNITTESTS` subdirectory of each library. We recommend that 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 are 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.
6482

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.
83+
All the stub source files are built in a 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`if it requires multiple stub libraries.
6684

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.
85+
The new stub file should follow the naming convention `<CLASS_NAME>_stub.cpp` for the source file and `<CLASS_NAME>_stub.h` for the header file. They should be built as part of their respective stub CMake library. Alternatively, create a stub library if `<CLASS_NAME>_stub` is an implementation for an external source not part of the Mbed OS.
6886

6987
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.
7088

@@ -220,15 +238,15 @@ This example does not use any Mbed OS code. If your unit tests do, remember to u
220238
221239
#### Mbed CLI 2
222240
223-
- Mbed CLI 2 is not supporting the `mbed test --unittests` command, please use CMake and a Make command directly.
241+
- Mbed CLI 2 does not currently support the `mbed test --unittests` command, please use CMake and a Make command directly.
224242
225243
#### Build tests directly with CMake
226244
227245
1. Create a build directory: `mkdir UNITTESTS/build`.
228246
1. Move to the build directory: `cd UNITTESTS/build`.
229247
1. Run CMake using a relative path to the `UNITTESTS` folder as the argument. So from `UNITTESTS/build` use `cmake ..-DMBED_BUILD_UNITTESTS=ON`:
230248
- Add `-g [generator]` if generating files other than Unix Makefiles. For example, for MinGW, use `-g "MinGW Makefiles"`.
231-
- Add `-DCMAKE_MAKE_PROGRAM=<value>`, `-DCMAKE_CXX_COMPILER=<value>` and `-DCMAKE_C_COMPILER=<value>` to use a specific Make programand compilers.
249+
- Add `-DCMAKE_MAKE_PROGRAM=<value>`, `-DCMAKE_CXX_COMPILER=<value>` and `-DCMAKE_C_COMPILER=<value>` to use a specific Make program and compilers.
232250
- Add `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
233251
- Add `-DCOVERAGE=True` to add coverage compiler flags.
234252
- Add `-Dgtest_disable_pthreads=ON` to run in a single thread.

0 commit comments

Comments
 (0)