STM32CubeIDE for Visual Studio Code Documentation

Table Of Contents

- STM32CubeIDE for Visual Studio Code
- Introduction
  - Overview
  - System requirements
  - Release note
- Basic Concepts
  - User interface
  - Command-line tools
  - Visual Studio Code extension packs
  - Bundles
  - CMake
  - Toolchains
  - STMicroelectronics Arm Clang Toolchain for STM32
- Getting Started
  - Installation
  - First project creation
- Workspace and extension workflow
  - Workspace overview
  - Extension commands
  - Project files
  - Multi-project workspaces
- Tutorials
  - Migrating from STM32CubeIDE for Visual Studio Code extension 2.x to 3.x
  - Dual-core STM32 projects
  - Power management
  - RTOS-based STM32 projects
  - Firmware security and integrity
- Development
  - Projects
  - Editing
  - Build
  - Debug
  - API manual
  - Integration with external tools
  - Testing and validation
- Troubleshooting
  - Frequently asked questions
  - Known issues
  - Support

### On this page

- Unit testing frameworks
  - Supported testing libraries
  - Writing and running unit tests
- Integration and system testing
  - Automated test execution
  - Test coverage analysis
- Hardware-in-the-Loop (HIL) testing
  - Setting up HIL environments
  - Debugging test failures

# Testing and validation

For RTOS-specific test planning and stress scenarios, see Testing and validation strategy.

## Unit testing frameworks

### Supported testing libraries

STM32CubeIDE projects can use several unit testing libraries for embedded systems development. Common frameworks include:

- Unity: A lightweight C unit testing framework for embedded environments.

- Ceedling: A build system and test runner based on Unity that provides automation and test management.

- CppUTest: A C/C++ testing framework for embedded systems with support for mocks and test doubles.

- Google Test: A framework commonly used in desktop environments that can be adapted for embedded testing with cross-compilation.

These libraries support writing and running unit tests to validate individual modules and functions in isolation.

### Writing and running unit tests

To write unit tests:

- Organize tests by module or functionality.

- Use assertions from the testing framework to verify expected behavior.

- Mock hardware dependencies to isolate logic under test.

- Automate test execution with build scripts or test runners such as Ceedling.

Running unit tests:

- On the host machine using cross-compiled test binaries.

- On the target hardware with debug probes or serial output.

- In continuous integration pipelines for automated validation.

## Integration and system testing

### Automated test execution

Automated test execution streamlines validation by running test suites without manual intervention. In Visual Studio Code, configure this with tasks or external scripts triggered after builds.

Best practices include:

- Schedule tests to run on code commits or nightly builds.

- Collect and report test results in standardized formats.

- Integrate with continuous integration tools for end-to-end automation.

### Test coverage analysis

Test coverage tools measure how much of the codebase is exercised by tests and identify untested areas.

For STM32CubeIDE projects:

- Use GCC –coverage flags (-fprofile-arcs -ftest-coverage) to instrument code.

- Generate coverage reports with tools such as gcov and lcov.

- Analyze reports to improve test completeness and quality.

## Hardware-in-the-Loop (HIL) testing

### Setting up HIL environments

Hardware-in-the-Loop testing runs embedded software on real hardware connected to simulated environments that mimic real-world inputs and conditions.

To set up HIL testing:

- Connect the STM32 target to simulation hardware or software simulators.

- Configure interfaces such as UART, CAN, or GPIO for test signal exchange.

- Develop test scenarios that stimulate hardware inputs and verify outputs.

- Use tools such as MATLAB/Simulink or dedicated HIL platforms for simulation control.

### Debugging test failures

Debugging failures in testing requires systematic analysis:

- Review test logs and output messages for error indications.

- Use debug probes and breakpoints to step through failing code sections.

- Verify hardware connections and signal integrity in HIL setups.

- Isolate failures by running smaller test cases or unit tests.

- Collaborate with hardware and software teams to resolve integration issues.