Skip to main content
Associate II
March 15, 2026
Question

Unit Testing Support with VS Code?

  • March 15, 2026
  • 2 replies
  • 249 views

Is there and/or will there be an approved off-target unit testing framework for STM32 (in my case, STM32H5)? I've been trying to stand up a test project generated by STM32CubeMX, imported into VS Code using Unity unit-testing framework, but running into pitfalls. In the past, I've used PlatformIO's with ease, was hoping the STM32 VSCode ext pack would be similar out the gate.

Over all, I'm aiming to test against the business logic and not needing a full-blown simulator. My rule of thumb is its good practice to do some kind of off-site (off-board) unit testing.

Even if there is a solid blog post with how to setup STM32 + CMake + Unity (or equivalent) and vanilla C using the CubeMX generated project, that would be most helpful. Most of the blog posts I find are either outdated, doing something custom, or a different architecture.  Yes, I'll fully admit, my strong points are MSVC and C#'s tooling for test frameworks, and not so much with CMake/CTest.

Thank you!

2 replies

SuessAuthor
Associate II
March 16, 2026

As an honorable mention, I've found the top 3 contenders for unit testing frameworks using C on off-target tests. However, it would be helpful to see a good clean example of how to implement with VS Code from a generated MX project

  • Unity unit-testing framework - C - Specialized for embedded (supported by Platform.IO)
  • CppUTest - C/C++ - Specialized for embedded and C++
  • GoogleTest - C/C++ mostly favored for C++
SuessAuthor
Associate II
April 25, 2026

Has anyone else been successful in creating Unit Tests using VSCode + CMake with STM32's extension set?

I was able to create a sample CMake + Unity example, and i ported over the basics to my STM32 C project (which builds). Its generating the Windows .EXE, however, the CTest is throwing a generic error, as if it can't find it.

Oddly enough, when I execute the "\build\Unit-Tests\Tests\Tests\suite_1_app.exe" it does execute and tells me that the tests pass

C:/xxxx/MyProject/Tests/SampleTest.c:19:test_fubar:PASS

-----------------------
1 Tests 0 Failures 0 Ignored
OK

 

VS Code's Build Output:

Below is a sample of the successful build, but fails to execute.

...
[main] Building folder: C:/xxxx/src/MyProject/build/Unit-Tests/Tests 
[build] Starting build
[driver] NOTE: You are building with preset Unit-Tests!, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: cube-cmake --build C:/xxxx/src/MyProject/build/Unit-Tests/Tests --
[build] [1/6] Building C object CMakeFiles/source_code.dir/Core/Src/app/StarbusBsp.c.obj
[build] [2/6] Building C object Tests/CMakeFiles/suite_1_app.dir/SampleTest.c.obj
[build] [3/6] Building C object Unity/CMakeFiles/UnityLib.dir/unity.c.obj
[build] [4/6] Linking C static library libsource_code.a
[build] [5/6] Linking C static library Unity\libUnityLib.a
[build] [6/6] Linking C executable Tests\suite_1_app.exe
[driver] Build completed: 00:00:01.038
[build] Build finished with exit code 0
[proc] The command: ctest --show-only=json-v1 -T test --output-on-failure --output-on-failure --no-tests=error failed with error: Error: spawn ctest ENOENT
[ctest] There was an error running ctest to determine available test executables