Building and running unit_test example on vscode extension
-
- Posts: 1
- Joined: Tue Apr 12, 2022 1:42 pm
Building and running unit_test example on vscode extension
I am trying to build the esp-idf unit_test example. I can build the project, but not the one including the test, has any done this? can give me some pointer on how?
-
- Posts: 9
- Joined: Fri May 13, 2022 6:08 am
Re: Building and running unit_test example on vscode extension
I have the same question...
-
- Posts: 9
- Joined: Fri May 13, 2022 6:08 am
Re: Building and running unit_test example on vscode extension
OK, so I am new to ESP32 and VS Code, but after studying about VS Code tasks, here is how I was able to build, flash, and run the unit tests for Espressif's examples / system / unit_test project.
Basically, the .vscode/tasks.json file defines tasks (such as build, flash, clean, and monitor) and these are all run from the main project directory. We need equivalent commands to be run from within the test/ directory. Changing the working directory which the task is executed from is accomplished using cwd inside of the options.
So, find the relevant section in the .vscode/tasks.json file, insert a copy of it at the end of the file, modify the label so it is unique, and insert cwd into the options. Also, these can all be grouped as test tasks. For example, here is my Test Build label:
Here are the five lines from above that were modified/inserted (note that one also has to add commas after some braces; the IDE will highlight JSON syntax problem areas to prompt you for them):
Similarly, create new tasks Test Flash and Test Clean. The existing ESP-IDF Monitor device icon at the bottom of the screen can be used without modification after Test Flash. The Task Monitor: Start the monitor command will flash the main code instead of the unit tests, so one could create a new Test Monitor task if desired, and make sure to modify its dependsOn to point to Test Flash instead.
There are two ways to run these tasks:
Basically, the .vscode/tasks.json file defines tasks (such as build, flash, clean, and monitor) and these are all run from the main project directory. We need equivalent commands to be run from within the test/ directory. Changing the working directory which the task is executed from is accomplished using cwd inside of the options.
So, find the relevant section in the .vscode/tasks.json file, insert a copy of it at the end of the file, modify the label so it is unique, and insert cwd into the options. Also, these can all be grouped as test tasks. For example, here is my Test Build label:
Code: Select all
{
"label": "Test Build - Build unit tests",
"type": "shell",
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py build",
"windows": {
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py build",
"options": {
"env": {
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}\\test"
}
},
"options": {
"env": {
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
},
"cwd": "${workspaceFolder}/test"
},
"problemMatcher": [
{
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
{
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
],
"group": {
"kind": "test",
"isDefault": false
}
}
Code: Select all
"label": "Test Build - Build unit tests",
"cwd": "${workspaceFolder}\\test"
"cwd": "${workspaceFolder}/test"
"kind": "test",
"isDefault": false
There are two ways to run these tasks:
- type (Ctrl+P), type "task " (make sure to type a space after task) and select from the list
- open the Command Palette (Ctrl+Shift+P), type "Tasks run test task", hit "Return" and select the task from the list
-
- Posts: 9
- Joined: Fri May 13, 2022 6:08 am
Who is online
Users browsing this forum: No registered users and 10 guests