Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Qt Test is a framework designed for unit testing applications and libraries built with Qt. It provides all the standard features commonly found in unit testing frameworks, making it easier to write unit tests for Qt-based projects.
We're happy to introduce the QtTest Runner - a Visual Studio Code extension for running Qt Tests
via the test explorer pane.
The main difference from existing test extensions is that you can now run a single test slot instead of the whole executable.
Also, unlike the ctest extension, we only build the target owning the test. There is no need for big rebuilds when debugging.
Other nice-to-haves include Go To Test, which opens the corresponding .cpp file directly from the test explorer:
And you can now execute a slot directly from the .cpp file editor, via context menu, by selecting the slot name:
.cpp
file with the test's implementation is automatically opened when there's a failureOnly CMake is supported at this time, as test discovery is done via CTest.
You'll need the official CMake extension. See our VSCode setup for Qt blog or just grab our template to get started quickly.
You'll also need a C++ debugger extension. This is usually either ms-vscode.cpptools
or vadimcn.vscode-lldb
aka CodeLLDB
.
You're expected to be using CMake's add_test(). Confirm by running ctest
in your build directory.
KDAB.QtTest.debugger
By default the extension will try to guess what the best debugger is. But you can and probably should explicitly choose which debugger to use. The best setting might be Existing Launch, which will use an existing launch config, this way you can reuse your source maps, pretty printers and launch env variables. When reusing an existing launch, its program and args are replaced by the test you're running.
KDAB.QtTest.CheckTestLinksToQtTestLib
Only available on Linux. Turn it on in case you have non-Qt tests executables that
you want to exclude from the list. It will invoke ldd
and see if libQtTest.so
is present. Patches are accepted for Windows and macOS support.
Test discovery is done by calling ctest --show-only=json-v1
, which lists all executables in a friendly JSON format. Then, for each
executable, we call -functions
which lists the available slots.
If you have a weird build system to support and you know of a nice test discovery approach, file an issue request and we'll try to guide you for a contribution.
ldd
and see if a test links to QtTest
.In the output pane, choose KDAB-QtTests and see if there are any errors.
Before reporting a bug, clear the output pane, reproduce the bug, and copy all output, paste it in the bug report.
Try pressing the reload button if the listing seems stale.
If no tests are reported, try running ctest -N inside the build directory. If that doesn't work either then it's a cmake
problem. Either there's really no tests added with add_test()
or the enable_testing()
call is missing in the root CMakeLists.txt
.
About KDAB
The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications. In addition to being leading experts in Qt, C++ and 3D technologies for over two decades, KDAB provides deep expertise across the stack, including Linux, Rust and modern UI frameworks. With 100+ employees from 20 countries and offices in Sweden, Germany, USA, France and UK, we serve clients around the world.
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Upgrade your applications from Qt 5 to Qt 6 with KDAB’s migration services. Get a free migration assessment and join a hands-on workshop to prepare your team for a successful transition!
Learn more
Learn Modern C++
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
Learn more
1 Comment
6 - Jun - 2024
Alex from Felgo
That's a great improvement for running tests in VSCode, I'm already curious to give it a try!