Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Getting Started

Installing CTest Lab

Install the extension through the VS Code marketplace. I recommend installing ms-vscode.cmake-tools, though it’s not required. CTest Lab uses commands and settings from cmake-tools if they’re available. This allows users to configure CMake and CTest in one place. If you do not have cmake-tools, then CTest Lab falls back to its own settings. VS Code activates CTest Lab if it detects a CMakeLists.txt file in your workspace. When activated, CTest Lab adds the Testing view to the main toolbar. Open this view to interact with your tests.

Discovering Tests

Before you can run tests, you must tell CTest Lab to look for the tests. There are three ways to discover tests:

  1. CTest Lab attempts to discover tests when it activates.
  2. You can run the Test: Refresh Tests command from the command palette.
  3. You can click the Refresh button in the Testing view.

Test discovery requires that you have configured your project. CTest Lab runs the ctest command to get the list of available tests. This also means that CTest Lab may not be able to discover some tests until you build them. For example, if you use Catch2’s catch_discover_tests() command, the tests are not actually added to the CTest system until you build them. If the list of tests does not look correct, try configuring and building your project, then refresh the tests.

Running Tests

After CTest Lab discovers your tests, you can run them in the Testing View. You can run all your tests with one command, or run individual tests. Use the play buttons in the Testing View to run tests.

If you have the cmake-tools extension installed, CTest Lab can run the default build command prior to running tests. You can disable this functionality with the ctest-lab.buildBeforeRun setting. Note that this does not affect test discovery. If you have new tests to discover, you need to manually build and run test discovery.

When the tests start, CTest Lab activates the CTest output channel so you can see the test output.

At this time, you cannot view individual test output via the Test View. This feature is on my roadmap, but I have not figured out how to make it work, yet.

The Testing View

CTest Lab provides ways for you to interact with your tests in the Testing View.

Disabled Tests

CTest Lab appends “(Disabled)” to the test name in the Testing view if the a test’s DISABLED property is set to true.

Skipped Tests

CTest sometimes skips a test, usually when a required resource is unavailable. These tests show as “Not Run” in the CTest output and as failed tests in the Test view.