Running and Writing Tests
May 13, 2026 · View on GitHub
This project uses CMake/CTest and Qt Test (Qt6::Test) for unit tests.
Run Tests
From the repository root, use tools/test.sh. It configures with qt-cmake, builds the default tree directory build, and runs CTest.
Configure, build, and run everything:
./tools/test.sh all
Other commands:
-
Run tests matching a regex (same as
ctest -R):./tools/test.sh one test_smoke ./tools/test.sh one "test_(util|json)" -
List discovered tests:
./tools/test.sh list -
Configure or build only:
./tools/test.sh configure ./tools/test.sh build
Environment overrides:
BUILD_DIR— build directory (default:build). Example:BUILD_DIR=build-tests ./tools/test.sh allQT_CMAKE_BIN— path toqt-cmakeif it is not onPATHCTEST_JUNIT_FILE— if set, CTest writes JUnit XML there (used in CI for GitLab test reports)
If you need raw CMake/CTest invocations instead of the script, use the same build directory and flags as tools/test.sh (qt-cmake -S . -B <dir> -DBUILD_TESTING=ON, then cmake --build and ctest --test-dir <dir>).
Add a New Test
Current tests live under tests/unit.
- Create a new test source file in
tests/unit(for exampletst_wallet.cpp). - Add the file as a new test executable in
tests/unit/CMakeLists.txtusingqt_add_executable(...). - Link at least
Qt6::CoreandQt6::Test. - Register the executable with CTest using
add_test(...).
Example CMake entry:
set(TEST_TARGET test_wallet)
qt_add_executable(${TEST_TARGET}
tst_wallet.cpp
)
target_link_libraries(${TEST_TARGET}
PRIVATE
Qt6::Core
Qt6::Test
)
add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET})