Skip to content

Add docs about new test macro #1003

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
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
10 changes: 10 additions & 0 deletions docs/tools/testing/testing_greentea.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ You can run tests throughout Mbed OS and for your project's code. They are locat

The fact that the code is located under this directory means that it is ignored when building applications and libraries. It is only used when building tests. This is important because all tests require a `main()` function, and building them with your application would cause multiple `main()` functions to be defined.

The macro `MBED_TEST_MODE` is defined when building tests with Mbed CLI versions 1.9.0 and later. You can wrap your application's `main()` function in a preprocessor check to prevent multiple `main()` functions from being defined:

```c++
#if !MBED_TEST_MODE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency shall this be #ifndef MBED_TEST_MODE? See https://github.com/ARMmbed/pelion-ready-example/blob/master/main.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with #if !MBED_TEST_MODE so you could also set MBED_TEST_MODE=0 for testing purposes. Specifying it as #ifndef would always evaluate to false, even if the macro was set to 0. A similar pattern is used within Mbed OS: ARMmbed/mbed-os#8957

int main() {
// Application code
}
#endif
```

In addition to being placed under a `TESTS` directory, test sources must exist under two other directories: a test group directory and a test case directory. The following is an example of this structure:

```
Expand Down