Out-of-tree unit testing

Although not clearly described in the documentation, I believe it is not possible to create unit tests outside of the mbed-os directory. I tried doing this but CMake does not discover my tests. When I move the test directory into mbed-os, it gets discovered. Has anyone managed to do this?

I’ve stumbled upon that issue as well a few month ago. I managed to fix it by duplicating the CMake file used for unit testing into my project, cleaning up a few things and was able to discover my tests.

Something like this:

It was about a year ago, so it might not be compatible with the latest version, but you’ll get the idea.

On another project, I’m also brainstorming on how to best include unit tests. I think I’ll go my own path with Catch2 or unity and not try to use mbed-os internal testing tools.

Thanks for the tip. I’ll check it out.

It would be interesting to hear from the maintainers if this is in the roadmap before investing time into it.

with the new cmake tools it will be much easier. You’ll define all you need in your main CMake list file, including your tests.