vscode-cpp-unit-testA simple and sweet VSCode extension to unit test C++ code. SetupTo use the extension, you'll need to:
NOTE: Please follow these instructions carefully! Getting startedIf you haven't already, install the C++ Unit Testing Framework by AutumnMoon from the VSCode Marketplace. Then, create and move into a new folder.
Now, create a Makefile and unit_tests.h file:
Wonderful! Now, open this folder in a new workspace:
If you see the testing panel open on the left-hand window, like in the image below then you're good to go. If not, ensure that the above two files are in your cwd, and again run Note! Whenever you plan to use the unit_test framework, please run unit_tests.hNow, we'll edit
For instance, your
Each test will effectively be run as its own 'main' by a driver that the extension creates for you. Valgrind will also be run on the test. A test is considered successful if it finishes execution; it will fail if either the main test fails or if valgrind fails (valgrind is run with --leak-check=full and --show-leak-kinds=all). Also, tests that diff against expected output are supported. Any file with the same name as a test in a folder named stdout/ will automatically be diff'd against the stdout of that test. See the sample/ for examples. The last thing to do is to set up the Makefile. MakefileYour
SaveMake sure you've saved both files. Run Your TestsNavigate back to Press each one to play its test. You can also head to the 'test explorer panel, where there is an overview of all tests, and a button to run all tests together. You can also create test groups with a comment above the first test in a group as follows:
(A regex is looking for the phrase Test groups are hierarchical - each group will run all groups below it. If you want to create more distinct test groups, you can create any number of files named XXX_tests.h, each of which has testing functions. These will be able to be run independently of one another. Note that each such file in your workspace will be That's it! Happy testing :) Matt PS: Many thanks to https://github.com/microsoft/vscode-extension-samples for having some great examples to work from. Changelog0.4.2
|