|
1 | 1 | # CppUTest Test Adapter for Visual Studio Code |
2 | 2 |
|
3 | 3 | [](https://github.com/bneumann/CppUTest-Test-Adapter/actions/workflows/unit_tests.yml) |
| 4 | +<a href="https://ko-fi.com/B0B836FAL"><img src="img/kofi.png" width="104px"></a> |
4 | 5 |
|
5 | | -This is the implementation for a [CppUTest](https://cpputest.github.io/) Test Adapter for VSCode. Check it out on the VSCode Market Place: [CppUTest Adapter](https://marketplace.visualstudio.com/items?itemName=bneumann.cpputest-test-adapter) |
6 | 6 |
|
7 | | -<a href="https://ko-fi.com/B0B836FAL"><img src="img/kofi.png" height="40"></a> |
| 7 | +A Visual Studio Code extension that integrates the [CppUTest](https://cpputest.github.io/) C/C++ unit testing framework into VS Code's Test Explorer. Run, debug, and manage your CppUTest tests seamlessly within your development environment. |
8 | 8 |
|
9 | | - |
| 9 | +--- |
| 10 | + |
| 11 | +## Features |
| 12 | +- **Run and debug** CppUTest tests directly from VS Code. |
| 13 | +- **Supports multiple test executables** and wildcards for flexible test discovery. |
| 14 | +- **Pre-launch tasks** to build tests before execution. |
| 15 | +- **Logging support** for debugging and troubleshooting. |
| 16 | + |
| 17 | +--- |
10 | 18 |
|
11 | 19 | ## Setup |
12 | 20 |
|
13 | | -To let this plugin know where your tests are set the ```cpputestTestAdapter.testExecutable``` to the executable of your tests. They are separated by semicolon and support wildcards, so you can add as many executables as you want: |
14 | | -``` |
| 21 | +### 1. Configure Test Executables |
| 22 | +Add the following to your VS Code `settings.json` to specify your test executables: |
| 23 | + |
| 24 | +```json |
15 | 25 | { |
16 | 26 | "cpputestTestAdapter.testExecutable": "${workspaceFolder}/test/testrunner;${workspaceFolder}/test/subFolder/ut_*", |
17 | | - "cpputestTestAdapter.testExecutablePath": "${workspaceFolder}/test" |
| 27 | + "cpputestTestAdapter.testExecutablePath": "\${workspaceFolder}/test" |
18 | 28 | } |
19 | 29 | ``` |
20 | 30 |
|
21 | | -Both settings support the ```${workspaceFolder}``` variable. The ```testExecutablePath``` determines the working directory: |
22 | | -- If set to a valid directory path, all test executables will be run from this directory |
23 | | -- If not set or set to an empty string, each test executable will be run from its own directory (the directory containing the executable) |
| 31 | +- ```testExecutable```: Path(s) to your test executables. Supports wildcards (*) and semicolon-separated lists. |
| 32 | +- ```testExecutablePath```: Working directory for running tests. If not set, each executable runs from its own directory. |
24 | 33 |
|
25 | | -To arrange for a task to be run prior to running tests or refreshing the test list, set ```cpputestTestAdapter.preLaunchTask``` to the name of a task from tasks.json. This can be used to rebuild the test executable, for example. |
| 34 | +Both settings support the ```${workspaceFolder}``` variable. |
26 | 35 |
|
27 | | -### Logging Configuration |
| 36 | +## Pre-Launch Task (Optional) |
| 37 | + |
| 38 | +To rebuild your tests before running, define a task in tasks.json and reference it: |
| 39 | +```json |
| 40 | +{ |
| 41 | + "cpputestTestAdapter.preLaunchTask": "build-tests" |
| 42 | +} |
| 43 | +``` |
| 44 | +## Logging |
| 45 | +Enable logging for debugging: |
28 | 46 |
|
29 | | -To enable debugging and troubleshooting, configure the logging options: |
30 | 47 | ```json |
31 | 48 | { |
32 | 49 | "cpputestTestAdapter.logpanel": true, |
33 | 50 | "cpputestTestAdapter.logfile": "C:/temp/cpputest-adapter.log" |
34 | 51 | } |
35 | 52 | ``` |
| 53 | +- logpanel: Shows logs in VS Code's Output panel ("CppUTest Test Adapter Log"). |
| 54 | +- logfile: Saves logs to a file. Use absolute paths and ensure the directory exists. |
36 | 55 |
|
37 | | -- ```logpanel```: Shows logs in VSCode's Output panel ("CppUTest Test Adapter Log") |
38 | | -- ```logfile```: Saves logs to a file. Use absolute paths (variables like ```${workspaceFolder}``` are not supported). Create the directory beforehand if it doesn't exist. |
39 | | - |
40 | | -If you want to use the debugging functions you will also need to setup a launch.json file with your debugger path and arguments etc. The adapter will take care of the rest. Hopefully. |
| 56 | +## Debugging |
| 57 | +To debug your tests, configure your launch.json like you would with any debugger (in this case gdb): |
41 | 58 |
|
| 59 | +```json |
| 60 | +{ |
| 61 | + "version": "0.2.0", |
| 62 | + "configurations": [ |
| 63 | + { |
| 64 | + "name": "Debug CppUTest", |
| 65 | + "type": "cppdbg", |
| 66 | + "request": "launch", |
| 67 | + "program": "${workspaceFolder}/test/testrunner", |
| 68 | + "args": [], |
| 69 | + "stopAtEntry": false, |
| 70 | + "cwd": "${workspaceFolder}", |
| 71 | + "environment": [], |
| 72 | + "externalConsole": false, |
| 73 | + "MIMode": "gdb", |
| 74 | + "miDebuggerPath": "/path/to/gdb" |
| 75 | + } |
| 76 | + ] |
| 77 | +} |
| 78 | +``` |
| 79 | +- The adapter automatically attaches to the test process. |
42 | 80 |
|
| 81 | +## Contributing |
| 82 | +Contributions are welcome! Feel free to open an issue or submit a pull request. |
0 commit comments