Unit Testing On Linux; Embedded Software Tests; Idf Unit Tests On Linux Host - Espressif ESP32-S2 Programming Manual

Table of Contents

Advertisement

Chapter 4. API Guides
Users should refer to the esp_event host-based unit test and its
as an example of a component mock.

4.31 Unit Testing on Linux

Note: Host testing with IDF is experimental for now. We try our best to keep interfaces stable but can't guarantee
it for now. Feedback via github or the forum on esp32.com is highly welcome, though and may influence the future
design of the host-based tests.
This article provides an overview of unit tests with IDF on Linux. For using unit tests on the target, please refer to
target based unit
testing.

4.31.1 Embedded Software Tests

Embedded software tests are challenging due to the following factors:
• Difficulties running tests efficiently.
• Lack of many operating system abstractions when interfacing with hardware, making it difficult to isolate code
under test.
To solve these two problems, Linux host-based tests with
efficient than unit tests on the target since they:
• Compile the necessary code only
• Don't need time to upload to a target
• Run much faster on a host-computer, compared to an ESP
Using the
CMock
framework also solves the problem of hardware dependencies. Through mocking, hardware details
are emulated and specified at run time, but only if necessary.
Of course, using code on the host and using mocks does not fully represent the target device. Thus, two kinds of tests
are recommended:
1. Unit tests which test program logic on a Linux machine, isolated through mocks.
2. System/Integration tests which test the interaction of components and the whole system. They run on the target,
where irrelevant components and code may as well be emulated via mocks.
This documentation is about the first kind of tests. Refer to
tests (the second kind of tests).

4.31.2 IDF Unit Tests on Linux Host

The current focus of the Linux host tests is on creating isolated unit tests of components, while mocking the compo-
nent's dependencies with CMock.
A complete implementation of IDF to run on Linux does not exist currently.
There are currently two examples for running IDF-built code on Linux host:
• An example
hello-world application
• A
unit test for NVS
Inside the component which should be tested, there is a separate directory host_test, besides the "traditional"
test directory or the test_apps directory. It has one or more subdirectories:
- host_test/
- fixtures/
Espressif Systems
.
Submit Document Feedback
esp_event/host_test/esp_event_unit_test/CMakeLists.txt
CMock
are introduced. Linux host-based tests are more
target based unit testing
1510
for more information on target
(continues on next page)
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF