Normal Test Cases; Multi-Device Test Cases - Espressif ESP32-S2 Programming Manual

Table of Contents

Advertisement

Chapter 4. API Guides
• Target based tests using a central unit test application which runs on the esp32s2. These tests use the Unity
<https://www.throwtheswitch.org/unity> unit test framework. They can be integrated into an ESP-IDF com-
ponent by placing them in the component's test subdirectory. For the most part, this document is about
target based tests.
• Linux-host based unit tests in which all the hardware is abstracted via mocks. Linux-host based tests are still
under development and only a small fraction of IDF components support them, currently. They are covered
here:
target based unit

4.30.1 Normal Test Cases

Unit tests are located in the test subdirectory of a component. Tests are written in C, and a single C source file can
contain multiple test cases. Test files start with the word "test".
Each test file should include the unity.h header and the header for the C module to be tested.
Tests are added in a function in the C file as follows:
TEST_CASE("test
name",
{
// Add test here
}
• The first argument is a descriptive name for the test.
• The second argument is an identifier in square brackets. Identifiers are used to group related test, or tests with
specific properties.
Note:
There is no need to add a main function with UNITY_BEGIN() and UNITY_END() in each test
case.
unity_platform.c will run UNITY_BEGIN() autonomously, and run the test cases, then call
UNITY_END().
The test subdirectory should contain a
component). ESP-IDF uses the Unity test framework located in the unity component. Thus, each test component
should specify the unity component as a component requirement using the REQUIRES argument. Normally,
components
should list their sources
of the SRC_DIRS argument in idf_component_register is advised.
Overall, the minimal test subdirectory CMakeLists.txt file should contain the following:
idf_component_register(SRC_DIRS "."
See
http://www.throwtheswitch.org/unity

4.30.2 Multi-device Test Cases

The normal test cases will be executed on one DUT (Device Under Test). However, components that require some
form of communication (e.g., GPIO, SPI) require another device to communicate with, thus cannot be tested normal
test cases. Multi-device test cases involve writing multiple test functions, and running them on multiple DUTs.
The following is an example of a multi-device test case:
void
gpio_master_test()
{
gpio_config_t slave_config
.pin_bit_mask
.mode
=
};
Espressif Systems
testing.
"[module name]"
component
CMakeLists.txt, since they are themselves components (i.e., a test
manually; for component tests however, this requirement is relaxed and the use
INCLUDE_DIRS "."
REQUIRES
unity)
for more information about writing tests in Unity.
=
{
=
1
<<
MASTER_GPIO_PIN,
GPIO_MODE_INPUT,
Submit Document Feedback
1503
(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?

Table of Contents

Save PDF