Skip to content

Commit 1d118dd

Browse files
minor edits to unit_testing.md and add note with link to "recently updated documentation" section
1 parent ed7d45d commit 1d118dd

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

docs/debugging-testing/testing/unit_testing.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Unit tests exercise code in small functional "units", such as a single function
88

99
## Prerequisites
1010

11-
Please install the following dependencies to use Mbed OS unit testing.
11+
You will need to 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.
@@ -72,19 +72,19 @@ In a terminal window:
7272
7373
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.
7474
75-
All the stub source files are built in a stub CMake library target (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.
75+
All the stub source files are built in a stub CMake library target (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.
7676
7777
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` 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.
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
8585
Libraries for fakes are under the `UNITTESTS/fakes` directory. These provide mock implementations that are meant to replace the stub version that does nothing. Usually, these will replace the header files as well as the source files and cannot be used together with their stub equivalents.
8686
87-
The upcoming [Example](#Example) section describes how to write a unit test for a dummy example class (Unit Under Test). The example walks you through creating a header library and a stub interface library using CMake.
87+
The upcoming [Example](#Example) section describes how to write a unit test for a dummy example class (Unit Under Test). The example walks you through creating a header library and a stub interface library using CMake.
8888
8989
### Test discovery
9090
@@ -131,13 +131,13 @@ With the following steps, you can write a unit test. This example creates dummy
131131
#endif
132132
```
133133
134-
1. Add a new `mbed-headers-example` interface library:
134+
1. Add a new `mbed-headers-example` interface library:
135135
136136
**mbed-os/stubs/CMakeLists.txt**
137-
137+
138138
```
139139
add_library(mbed-headers-example INTERFACE)
140-
140+
141141
target_include_directories(mbed-headers-example
142142
INTERFACE
143143
${mbed-os_SOURCE_DIR}/example
@@ -179,35 +179,35 @@ With the following steps, you can write a unit test. This example creates dummy
179179
180180
181181
1. Create an example stub directory in `mbed-os/UNITTESTS/stubs/example`.
182-
1. Create the following example interface api stub source in `mbed-os/UNITTESTS/stubs/example`
182+
1. Create the following example interface api stub source in `mbed-os/UNITTESTS/stubs/example`
183183
184184
**example_interface_api_stub.c**
185185
186186
```
187187
#include "example_interface/example_interface_api.h"
188-
188+
189189
example_interface_status_t example_interface_api_init()
190190
{
191191
return STATUS_OK;
192192
}
193-
193+
194194
void example_interface_api_start(void)
195195
{
196-
196+
197197
}
198-
198+
199199
```
200200
201201
**CMakeLists.txt**
202202
203203
```
204204
add_library(mbed-stubs-example-interface)
205-
205+
206206
target_sources(mbed-stubs-example-interface
207207
PRIVATE
208208
example_interface_api_stub.c
209209
)
210-
210+
211211
target_link_libraries(mbed-stubs-example-interface
212212
PRIVATE
213213
mbed-headers
@@ -273,22 +273,22 @@ With the following steps, you can write a unit test. This example creates dummy
273273
set(TEST_NAME myclass-unittest)
274274
275275
add_executable(${TEST_NAME})
276-
276+
277277
target_sources(${TEST_NAME}
278278
PRIVATE
279279
${mbed-os_SOURCE_DIR}/example/tests/unittests/MyClass/MyClass.cpp
280280
test_MyClass.cpp
281281
)
282-
282+
283283
target_link_libraries(${TEST_NAME}
284284
PRIVATE
285285
mbed-headers
286286
mbed-stubs
287287
gmock_main
288288
)
289-
289+
290290
add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME})
291-
291+
292292
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "example")
293293
```
294294
@@ -366,4 +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`.
369+
- **Solution**: Make sure gnm (binutils) is not installed. Uninstall binutils with `brew uninstall binutils`.

docs/introduction/introduction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Our [quick start](../quick-start/index.html) guides show how to build an example
2424

2525
## Recently updated documentation
2626

27+
- We've updated the [Unit testing](../debug-test/unit-testing.html) information to reflect changes to the version of CMake used. You will need to update to CMake version 3.19 or above and alter your test code structure.
2728
- A new [tutorial about link time optimization](../apis/link-time-optimization.html).
2829
- A new [PSA porting guide](../porting/porting-security.html).
2930
- New information about [API life cycle ](../introduction/versions-and-releases.html#the-api-life-cycle) and how to [contribute experimental APIs](../contributing/software-design.html#experimental-apis) and [use them in an application](../program-setup/build-rules.html#label-directories).

0 commit comments

Comments
 (0)