1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-20 16:55:49 +00:00
Files
esphome/tests/components
J. Nick Koston e5c4b50a1a Merge upstream/dev into integration
Resolved conflicts in:
- esphome/components/fan/fan.cpp: Preserved pointer-based preset mode optimization
- esphome/components/fan/fan_traits.h: Kept cstring include for strcmp
- esphome/components/web_server_idf/web_server_idf.cpp: Kept float_buf_size constant

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 19:42:06 -06:00
..
2025-10-22 22:24:17 -04:00
2025-11-02 16:22:49 -06:00
2025-11-02 16:20:30 -06:00
2025-11-01 17:45:42 +11:00
2025-09-26 08:53:21 +12:00
2025-10-28 08:32:24 +10:00

How to write C++ ESPHome unit tests

  1. Locate the folder with your component or create a new one with the same name as the component.
  2. Write the tests. You can add as many .cpp and .h files as you need to organize your tests.

IMPORTANT: wrap all your testing code in a unique namespace to avoid linker collisions when compiling testing binaries that combine many components. By convention, this unique namespace is esphome::component::testing (where "component" is the component under test), for example: esphome::uart::testing.

Running component unit tests

(from the repository root)

./script/cpp_unit_test.py component1 component2 ...

The above will compile and run the provided components and their tests.

To run all tests, you can invoke cpp_unit_test.py with the special --all flag:

./script/cpp_unit_test.py --all

To run a specific test suite, you can provide a Google Test filter:

GTEST_FILTER='UART*' ./script/cpp_unit_test.py uart modbus

The process will return 0 for success or nonzero for failure. In case of failure, the errors will be printed out to the console.