Skip to content

Commit ed7d45d

Browse files
committed
Incorporated the review comments
1 parent 23a1231 commit ed7d45d

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

docs/debugging-testing/testing/unit_testing.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ In a terminal window:
6363
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
6464
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
6565
1. Add MinGW, CMake and Python into system PATH.
66-
1. Install the addition Python package `gcovr` for code coverage report:
66+
1. Install the additional Python package `gcovr` for code coverage report:
6767
```
6868
pip install "gcovr>=4.1"
6969
```
@@ -78,7 +78,7 @@ All the stub source files are built in a stub CMake library target (e.g `mbed-st
7878
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 of an external source, not part of Mbed OS.
7979
8080
81-
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.
81+
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` directory 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.
8282
8383
All the stub libraries and header libraries are defined under `UNITTESTS/stubs/` directory.
8484
@@ -94,7 +94,7 @@ For the build system to build a unit test, pass the `ON` value to `BUILD_TESTING
9494
9595
### Writing unit tests
9696
97-
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.
97+
A unit test suite consists of one or more test cases, which should cover all the functions in a class under test. Any external dependencies should be 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.
9898
9999
Please see the [documentation for Google Test](https://github.com/google/googletest/blob/master/docs/primer.md) to learn how to write unit tests using its framework. See the [documentation for Google Mock](https://github.com/google/googletest/tree/master/googlemock) if you want to write and use C++ mock classes instead of stubs.
100100
@@ -133,17 +133,17 @@ With the following steps, you can write a unit test. This example creates dummy
133133
134134
1. Add a new `mbed-headers-example` interface library:
135135
136-
### Stub CMake input source file
137-
138-
```
139-
add_library(mbed-headers-example INTERFACE)
140-
141-
target_include_directories(mbed-headers-example
142-
INTERFACE
143-
${mbed-os_SOURCE_DIR}/example
144-
${mbed-os_SOURCE_DIR}/example/include
145-
${mbed-os_SOURCE_DIR}/example/include/example
146-
)
136+
**mbed-os/stubs/CMakeLists.txt**
137+
138+
```
139+
add_library(mbed-headers-example INTERFACE)
140+
141+
target_include_directories(mbed-headers-example
142+
INTERFACE
143+
${mbed-os_SOURCE_DIR}/example
144+
${mbed-os_SOURCE_DIR}/example/include
145+
${mbed-os_SOURCE_DIR}/example/include/example
146+
)
147147
```
148148
149149
1. Add the newly created `mbed-headers-example` library into existing `target_link_libraries` of target `mbed-headers` in `mbed-os/UNITTESTS/stubs/CMakeLists.txt`:
@@ -198,7 +198,7 @@ With the following steps, you can write a unit test. This example creates dummy
198198
199199
```
200200
201-
### CMake input source file
201+
**CMakeLists.txt**
202202
203203
```
204204
add_library(mbed-stubs-example-interface)
@@ -268,7 +268,7 @@ With the following steps, you can write a unit test. This example creates dummy
268268
}
269269
```
270270
271-
### CMake input source file for UUT (Unit Under Test)
271+
**CMakeLists.txt**
272272
```
273273
set(TEST_NAME myclass-unittest)
274274
@@ -298,7 +298,7 @@ This example does not use any Mbed OS code. If your example depends on Mbed OS c
298298
299299
#### Mbed CLI 1
300300
301-
- Install [Mbed CLI 1](../build-tools/mbed-cli-1.html) using the `pip install mbed-cli` command in Debian, Ubuntu, macOS or Windows and make sure that installed Mbed CLI 1 version 1.8.0 or newer.
301+
- Install [Mbed CLI 1](../build-tools/mbed-cli-1.html) version 1.8.0 or newer using the `pip install "mbed-cli>=1.8.0"` command in Debian, Ubuntu, macOS or Windows.
302302
303303
- 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).
304304
@@ -327,10 +327,10 @@ Run a test binary in the build directory to run a unit test suite. To run multip
327327
1. Create a build directory from Mbed OS root: `mkdir cmake_build`.
328328
1. Run CTest using a relative path to the Mbed OS root directory and created build directory `cmake_build` as an argument. From Mbed OS root use `ctest --build-and-test . cmake_build --build-generator Ninja --build-options -DBUILD_TESTING=ON --test-command ctest`.
329329
330-
- `--build-generator [generator]` to specify the [build generator](https://cmake.org/cmake/help/v3.19/manual/cmake-generators.7.html#cmake-generators) and above reference command uses `Ninja`.
330+
- `--build-generator [generator]` specifies the [build generator](https://cmake.org/cmake/help/v3.19/manual/cmake-generators.7.html#cmake-generators), the example above uses `Ninja`.
331331
332332
- `--build-options [options]` to specify for Mbed OS unit tests CMake configuration, not for the build tool (e.g --build-options -DBUILD_TESTING=ON)
333-
- `--test-command [command]` to specify the command get invoked after the CMake build.
333+
- `--test-command [command]` to specify the command to invoke after the CMake build.
334334
- See the [CTest manual](https://cmake.org/cmake/help/v3.19/manual/ctest.1.html) for more information.
335335
336336
#### Run tests with GUI test runner
@@ -366,5 +366,4 @@ Use Mbed CLI to generate code coverage reports. For advanced use, follow these s
366366
- **Solution**: Remove sh.exe from the system path.
367367
368368
**Problem:** (Mac OS) CMake compiler check fails on Mac OS Mojave when using GCC-8.
369-
- **Solution**: Make sure gnm (binutils) is not installed. Uninstall binutils with `brew uninstall binutils`.
370-
369+
- **Solution**: Make sure gnm (binutils) is not installed. Uninstall binutils with `brew uninstall binutils`.

0 commit comments

Comments
 (0)