Skip to content

Commit abcf3dc

Browse files
Unity runner and parser for unit testing feature (#1681)
* use serialport to read unity output parse test results * use readSerialPort instead * rm console log references and pytest * rm isCapturing from UnitySerialCapture * update docs, rm pyTestEmbeddedServices setting * fix doc issue * rm installPyTest command * fix docs issues * update docs removed pytest cmd
1 parent 4bde6af commit abcf3dc

25 files changed

+782
-634
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Press <kbd>F1</kbd> or click menu `View` -> `Command Palette...` to show Visual
227227
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>D</kbd></td>
228228
</tr>
229229
<tr>
230-
<td rowspan=5 align="center">Project creation</td>
230+
<td rowspan=4 align="center">Project creation</td>
231231
<td>Create New ESP-IDF Component</td>
232232
<td>Create a new component in the current directory based on ESP-IDF component template.</td>
233233
<td></td>
@@ -442,32 +442,24 @@ Press <kbd>F1</kbd> or click menu `View` -> `Command Palette...` to show Visual
442442
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>G</kbd></td>
443443
</tr>
444444
<tr>
445-
<td rowspan=2 align="center">Unit Testing</td>
445+
<td rowspan=3 align="center">Unit Testing</td>
446446
<td>"Unit Test: Build Unit Test App"</td>
447447
<td>Copy the unit test app in the current project, build the current project. More information in <a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">Unit testing documentation</a>.</td>
448448
<td></td>
449449
<td></td>
450450
</tr>
451451
<tr>
452-
<td rowspan=2 align="center">Unit Testing</td>
453452
<td>Unit Test: Flash Unit Test App</td>
454453
<td>Flash the unit test application to the connected device. More information in <a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">Unit testing documentation</a>.</td>
455454
<td></td>
456455
<td></td>
457456
</tr>
458457
<tr>
459-
<td rowspan=2 align="center">Unit Testing</td>
460458
<td>Unit Test: Build and Flash Unit Test App for Testing</td>
461459
<td>Copy the unit test app in the current project, build the current project and flash the unit test application to the connected device. More information in <a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">Unit testing documentation</a>.</td>
462460
<td></td>
463461
<td></td>
464462
</tr>
465-
<tr>
466-
<td>Unit Test: Install ESP-IDF PyTest Requirements</td>
467-
<td>Install the ESP-IDF Pytest requirement packages to be able to execute ESP-IDF unit tests. More information in <a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">Unit Testing documentation</a>.</td>
468-
<td></td>
469-
<td></td>
470-
</tr>
471463
<tr>
472464
<td rowspan=10 align="center">Scripts and Tools</td>
473465
<td>Run idf.py reconfigure Task</td>

README_CN.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
9797

9898
10. 根据 ESP-IDF 文档中的要求来配置驱动程序,详情请参考[配置 JTAG 接口](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-guides/jtag-debugging/configure-ft2232h-jtag.html)
9999

100-
11. 在调试设备之前,先按 <kbd>F1</kbd> 输入 **ESP-IDF:选择 OpenOCD 开发板配置**,选择设备的 OpenOCD 开发板配置文件。点击状态栏图标 ![openocd](./media/readme/openocd.png) 或按 <kbd>F1</kbd> 输入 **ESP-IDF:OpenOCD 管理器** 命令来测试连接。可以在菜单栏中的`查看` -> `输出`里选择下拉列表中的 `ESP-IDF` 来查看输出信息。
100+
11. 在调试设备之前,如果您使用的是已连接的 ESP-IDF 开发板,OpenOCD 配置将根据您连接的开发板自动选择,包括 USB 位置(如果可用)(需要 OpenOCD 版本 v0.12.0-esp32-20240821 或更高)。否则,您可以按 <kbd>F1</kbd> 输入 **ESP-IDF:选择 OpenOCD 开发板配置** 手动选择设备的 OpenOCD 开发板配置文件。点击状态栏图标 ![openocd](./media/readme/openocd.png) 或按 <kbd>F1</kbd> 输入 **ESP-IDF:OpenOCD 管理器** 命令来测试连接。可以在菜单栏中的`查看` -> `输出`里选择下拉列表中的 `ESP-IDF` 来查看输出信息。
101101

102102
> **注意:** 可以使用 **ESP-IDF:OpenOCD 管理器** 命令或者点击 VS Code 状态栏中的 `OpenOCD Server (Running | Stopped)` 按钮来启动或停止 OpenOCD。
103103
104-
12. 确保项目已经构建并烧录,OpenOCD 连接正常,调试器能正常工作。按 <kbd>F5</kbd> 启动调试会话。调试会话的输出可在菜单栏中选择`查看` -> `调试控制台`进行查看。
104+
12. 如果您想启动调试会话,只需按 <kbd>F5</kbd>(确保项目已构建、烧录,并且 OpenOCD 正确连接以便调试器正常工作)。调试会话的输出可在菜单栏中选择`查看` -> `调试控制台`进行查看。
105105

106106
如有问题,请参阅[故障排除](#Troubleshooting)部分。
107107

108108
# 拓展阅读
109109

110110
所有的教程、命令和功能都收录在[适用于 VS Code 的 ESP-IDF 扩展文档中心](https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/)
111111

112-
# 可用命令列表
112+
## 所有可用命令
113113

114114
按 <kbd>F1</kbd> 或点击菜单栏中的`查看` -> `命令面板`,输入 **ESP-IDF** 即可查看 ESP-IDF 扩展所支持的所有命令。
115115

@@ -227,21 +227,15 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
227227
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>D</kbd></td>
228228
</tr>
229229
<tr>
230-
<td rowspan=5 align="center">创建项目</td>
231-
<td>基于模板创建新项目</td>
232-
<td>使用扩展中的项目模板来创建一个新的 ESP-IDF 项目。</td>
233-
<td><kbd>⌘</kbd> <kbd>I</kbd> <kbd>C</kbd></td>
234-
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>C</kbd></td>
235-
</tr>
236-
<tr>
237-
<td>创建新的空项目</td>
238-
<td>询问新项目名称,选择创建项目的目录,并显示通知以打开新创建的项目。</td>
230+
<td rowspan=4 align="center">创建项目</td>
231+
<td>创建新 ESP-IDF 组件</td>
232+
<td>在当前目录下,基于 ESP-IDF 组件模板创建新组件。</td>
239233
<td></td>
240234
<td></td>
241235
</tr>
242236
<tr>
243-
<td>创建新 ESP-IDF 组件</td>
244-
<td>在当前目录下,基于 ESP-IDF 组件模板创建新组件。</td>
237+
<td>创建新的空项目</td>
238+
<td>询问新项目名称,选择创建项目的目录,并显示通知以打开新创建的项目。</td>
245239
<td></td>
246240
<td></td>
247241
</tr>
@@ -448,15 +442,21 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
448442
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>G</kbd></td>
449443
</tr>
450444
<tr>
451-
<td rowspan=2 align="center">单元测试</td>
452-
<td>单元测试:构建并烧录单元测试应用程序</td>
453-
<td>复制当前项目中的单元测试应用程序,构建当前项目并将单元测试应用程序烧录到连接的设备上。详情请参阅<a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">单元测试</a>。</td>
445+
<td rowspan=3 align="center">单元测试</td>
446+
<td>单元测试:构建单元测试应用程序</td>
447+
<td>构建当前项目的单元测试应用程序。详情请参阅<a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">单元测试</a>。</td>
454448
<td></td>
455449
<td></td>
456450
</tr>
457451
<tr>
458-
<td>单元测试:安装 ESP-IDF PyTest 依赖项</td>
459-
<td>安装 ESP-IDF Pytest 依赖项,以便能够执行 ESP-IDF 单元测试。详情请参阅<a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">单元测试</a>。</td>
452+
<td>单元测试:烧录单元测试应用程序</td>
453+
<td>将当前项目的单元测试应用程序烧录到连接的设备上。详情请参阅<a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">单元测试</a>。</td>
454+
<td></td>
455+
<td></td>
456+
</tr>
457+
<tr>
458+
<td>单元测试:构建并烧录单元测试应用程序</td>
459+
<td>复制当前项目中的单元测试应用程序,构建当前项目并将单元测试应用程序烧录到连接的设备上。详情请参阅<a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html">单元测试</a>。</td>
460460
<td></td>
461461
<td></td>
462462
</tr>
@@ -557,11 +557,11 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
557557

558558
## tasks.json 模板任务
559559

560-
使用 **ESP-IDF:基于模板创建新项目** 命令创建项目时,会包含 tasks.json 模板。按 <kbd>F1</kbd> 并输入 `Tasks: Run task`,选择执行以下任一任务:
560+
使用 **ESP-IDF:新建项目** 命令创建项目时,会包含 tasks.json 模板。按 <kbd>F1</kbd> 并输入 `Tasks: Run task`,选择执行以下任一任务:
561561

562562
1. `Build` - 构建项目
563563
2. `Set Target to esp32` - 选择 ESP32 为对象
564-
3. `Set Target to esp32s2` - - 选择 ESP32-S2 为对象
564+
3. `Set Target to esp32s2` - 选择 ESP32-S2 为对象
565565
4. `Clean` - 清除项目
566566
5. `Flash` - 烧录设备
567567
6. `Monitor` - 启动监视终端
@@ -574,9 +574,9 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
574574

575575
如果遇到问题,请检查以下方面是否有错误:
576576

577-
> **注意:** `idf.OpenOCDDebugLevel` 配置项设为 3 或更高值,OpenOCD 服务器将输出调试日志
577+
> **注意:** 在您的 <project-directory>/.vscode/settings.json 中将 `idf.OpenOCDDebugLevel` 配置项设为 3 或更高值,以在 `ESP-IDF` 输出中显示 OpenOCD 服务器的调试级别日志
578578
579-
> **注意:** `<project-directory>/.vscode/launch.json` 文件中的 `logLevel` 配置项设为 3 或更高值,调试适配器将输出详细日志
579+
> **注意:** 在您的 <project-directory>/.vscode/launch.json 中设置 `verbose: true` 以获得更详细的调试适配器输出
580580
581581
1. 在 VS Code 菜单栏中选择**查看** > **输出** > **ESP-IDF**。此输出信息有助于了解扩展的运行状况。
582582
2. 在 VS Code 菜单栏中选择**查看** > **命令面板...**,输入 `ESP-IDF:诊断命令`,该命令将生成环境配置的报告并复制到剪贴板中,报告内容可粘贴至任意位置。
@@ -587,11 +587,13 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
587587

588588
4. 在 VS Code 菜单栏中选择**帮助** > **切换开发人员工具**,Console 选项卡中会显示与扩展相关的错误信息,可自行复制。
589589

590-
5. VS Code 支持不同级别的设置,如:**全局(用户设置)****工作区****工作区文件夹**,请确保项目配置正确。运行 `ESP-IDF:诊断命令`得到的结果可能来自于用户设置,而非工作区文件夹。
590+
5. 在 VS Code 菜单栏中选择**查看** > **输出** > **Extension Host**。此输出信息有助于了解扩展激活期间发生的情况。如果扩展命令都不工作,您可以分享此处的输出来查看错误堆栈。
591+
592+
6. VS Code 支持不同级别的设置,如:**全局(用户设置)****工作区****工作区文件夹**,请确保项目配置正确。运行 `ESP-IDF:诊断命令`得到的结果可能来自于用户设置,而非工作区文件夹。
591593

592-
6. 查看 [OpenOCD 故障排除 FAQ](https://github.com/espressif/OpenOCD-esp32/wiki/Troubleshooting-FAQ),可帮助进行应用追踪及调试,并解决 `OpenOCD` 输出中显示的其他相关问题。
594+
7. 查看 [OpenOCD 故障排除 FAQ](https://github.com/espressif/OpenOCD-esp32/wiki/Troubleshooting-FAQ),可帮助进行应用追踪及调试,并解决 `OpenOCD` 输出中显示的其他相关问题。
593595

594-
7. 有时 VS Code 中配置的默认 shell(Powershell、zsh、sh 等)可能会影响扩展的行为。请确保环境中未设置 MSYS/MinGW,且变量与终端行为不冲突。`ESP-IDF:诊断命令`会显示运行构建、烧录和监视任务时扩展检测到的 shell。详情请参考[此处](https://code.visualstudio.com/docs/terminal/profiles)
596+
8. 有时 VS Code 中配置的默认 shell(Powershell、zsh、sh 等)可能会影响扩展的行为。请确保环境中未设置 MSYS/MinGW,且变量与终端行为不冲突。`ESP-IDF:诊断命令`会显示运行构建、烧录和监视任务时扩展检测到的 shell。详情请参考[此处](https://code.visualstudio.com/docs/terminal/profiles)
595597

596598
如果出现 Python 包错误,请尝试使用 **ESP-IDF:安装 ESP-IDF Python 包** 命令重新安装所需的 Python 包,或通过 **ESP-IDF:配置 ESP-IDF 扩展** 命令重新设置。
597599

docs_espressif/en/additionalfeatures/unit-testing.rst

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,64 +41,20 @@ To add tests for a ``testable`` component, define a ``test`` subdirectory and ad
4141

4242
This structure is from the `ESP-IDF unit_test example <https://github.com/espressif/esp-idf/tree/master/examples/system/unit_test>`_, which can serve as a reference.
4343

44-
.. note::
45-
46-
You can customize the test file discovery pattern by modifying the ``idf.unitTestFilePattern`` setting in your VS Code settings. This allows you to use different naming conventions or directory structures for your test files.
47-
48-
pytest Embedded Services Configuration
49-
--------------------------------------
50-
51-
The extension uses `pytest-embedded <https://docs.espressif.com/projects/pytest-embedded/en/latest/index.html>`_ to run tests on ESP-IDF devices. The ``idf.pyTestEmbeddedServices`` configuration setting allows you to specify which embedded services to use when running pytest commands.
52-
53-
By default, the extension uses ``["esp", "idf"]`` as the embedded services. These services provide the following functionality:
54-
55-
* **esp**: Enables Espressif-specific functionality, including automatic target detection and port confirmation using ``esptool``.
56-
* **idf**: Provides ESP-IDF project support, including automatic flashing of built binaries and parsing of binary information.
57-
58-
You can customize the embedded services by modifying the ``idf.pyTestEmbeddedServices`` setting in your VS Code settings. For example, you might want to add following additional services:
59-
60-
* **serial**: For basic serial port communication.
61-
* **jtag**: For OpenOCD/GDB utilities.
62-
* **qemu**: For running tests on QEMU instead of real hardware.
63-
* **wokwi**: For running tests on the Wokwi simulation platform.
64-
65-
For a complete list of available services and their capabilities, refer to the `pytest-embedded Services Documentation <https://docs.espressif.com/projects/pytest-embedded/en/latest/concepts/services.html>`_.
66-
67-
.. note::
68-
69-
The embedded services you choose will affect the pytest command that gets executed. Make sure the services you specify are compatible with your testing environment and requirements.
70-
71-
Running the Tests
72-
-----------------
44+
Running the tests
45+
--------------------------------------------
7346

7447
When you click the ``Testing`` Tab in the `Visual Studio Code Activity bar <https://code.visualstudio.com/docs/getstarted/userinterface>`_, the extension will try to find all test files and test cases and save the list of test components to add later in step 3.
7548

76-
.. note::
77-
78-
User needs to install ESP-IDF pytest Python requirements by selecting menu ``View`` > ``Command Palette`` and typing ``Unit Test: Install ESP-IDF pytest requirements``. Select the command and see the pytest package installation output.
79-
80-
When you press the ``run`` button on a test, it will configure the current project before the tests as follows:
81-
82-
1. Check that pytest requirements from ESP-IDF are satisfied.
83-
84-
.. note::
85-
86-
Unit tests in this extension requires `ESP-IDF pytest requirements <https://github.com/espressif/esp-idf/blob/master/tools/requirements/requirements.pytest.txt>`_ to be installed in your Python virtual environment.
49+
When it press the run button on a test, it will configure the current project before the tests as follows:
8750

88-
2. Install ESP-IDF pytest requirements if they are not found in the python current virtual environment specified in ``idf.toolsPath`` configuration setting in ``settings.json``.
51+
1. Copy the unity-app from the extension template and add the test components to the main CMakeLists.txt ``TEST_COMPONENTS`` cmake variable. The extension unity-app is a basic ESP-IDF application with a unity menu that will be built and flashed on the current **idf.port** serial device with all test cases that were found during exploration step.
8952

90-
3. Copy the ``unity-app`` from the extension template, and add the required test components to the ``TEST_COMPONENTS`` CMake variable in the main ``CMakeLists.txt``. The ``unity-app`` provided by the extension is a simple ESP-IDF application that includes a Unity menu. It will be built and flashed to the serial device defined by ``idf.port``, together with all the test cases discovered during the exploration step.
53+
2. Build and flash the unity-app to the device.
9154

92-
.. note::
93-
94-
You can also create, build and flash the unity test application using the ``Unit Test: Install ESP-IDF pytest requirements`` extension command, which will copy, build, and flash the generated unit testing application to your device.
95-
96-
4. Run `pytest-embedded <https://docs.espressif.com/projects/pytest-embedded/en/latest/index.html>`_, a plugin that extends pytest to run on ESP-IDF devices and output the results as an XML file in the ``unity-app`` directory. This is executed as an extension task, and the output is shown in the terminal (similar to build and flash tasks). The pytest command uses the embedded services specified in the ``idf.pyTestEmbeddedServices`` configuration setting (default: ``["esp", "idf"]``).
97-
98-
.. note::
99-
100-
You can customize the embedded services used by pytest by modifying the ``idf.pyTestEmbeddedServices`` setting in your VS Code settings. This allows you to specify different services or add additional ones as needed for your testing environment.
55+
.. note::
56+
You can also create, build and flash the unity test application using the **ESP-IDF Unit Test: Build Unit Test App** and **ESP-IDF Unit Test: Flash Unit Test App** extension commands respectively, which will copy build and flash to your device the generated unit testing application.
10157

102-
5. The XML results file is parsed, and test results are updated in the ``Testing`` tab with test duration.
58+
3. Capture the serial output from the device and parse the test results to show them in the ``Testing`` tab. The output from serial port is also shown in the ``ESP-IDF`` output channel.
10359

104-
6. You can refresh the tests and build the ``unity-app`` again with the ``Refresh Tests`` button from the ``Testing`` tab.
60+
4. You can refresh the tests and build the unity-app again with the ``Refresh Tests`` button from the ``Testing`` tab.

docs_espressif/en/commands.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,3 @@ All commands start with ``ESP-IDF:``.
136136
- Flash the unit test application for the current project to the connected device. More information can be found in :ref:`Unit Testing Documentation <unit testing>`.
137137
* - Unit Test: Build and Flash Unit Test App for Testing
138138
- Copy the unit test app in the current project, build the current project and flash the unit test application to the connected device. More information can be found in :ref:`Unit Testing Documentation <unit testing>`.
139-
* - Unit Test: Install ESP-IDF Pytest Requirements
140-
- Install the ESP-IDF Pytest requirement packages to be able to execute ESP-IDF unit tests. More information can be found in :ref:`Unit Testing Documentation <unit testing>`.

0 commit comments

Comments
 (0)