Provide a single qmake test executable with named Qt Test cases and a standard make check entry point. Cover object-history compaction, cancellation, merging, and property-key comparisons with checks that remain active in release builds, and document how to add tests. Build and run the tests in Linux and macOS CI and add a Windows x64 job using MSVC 2022 and Qt 6. Enable pull request and manual runs alongside master pushes, preserve JUnit reports on failures, and update existing checkout and cache actions. Validation: macOS Qt 6.10 release tests and actionlint passed. Confirmed a failing assertion produces a nonzero check result and a JUnit failure. Closes #1050
2.6 KiB
LeoCAD tests
All tests run in one Qt Test executable, leocad_tests. The current tests cover
object history and property-key comparisons, including 8,000 deterministic
randomized undo/redo and merge transitions.
The executable creates a QCoreApplication; it does not open windows or require
an OpenGL context, the parts library, or network access. It uses the same Qt
headers as the application, plus Qt Test, and supports Qt 5 and Qt 6.
Build and run
From the repository root, with the intended Qt installation's qmake on PATH:
mkdir -p build/tests
cd build/tests
qmake ../../tests/tests.pro CONFIG+=release CONFIG-=debug
make -j
make check
On Windows, use the make tool for the selected Qt kit, such as nmake.
To list test functions or run one function directly:
./leocad_tests -functions
./leocad_tests HistoryStoresOnlyChangedObjects
On Windows, the executable is leocad_tests.exe and may be in release/.
make check handles the configured executable location.
To write both console output and a JUnit report:
make check TESTARGS="-o test-results.xml,junitxml -o -,txt"
Add tests
- Declare a named
voidfunction underprivate slotsinlc_tests.h. - Define it in the relevant test source file as
void lcTests::FunctionName(). - If adding a new source file, list it in
tests.pro.
Use QVERIFY, QCOMPARE, or other Qt Test checks so assertions remain active in
release builds and failures identify the function and source line. Each test
must create its own state. Use temporary directories for writable fixtures and
fixed seeds for randomized tests; include the seed and iteration in failures.
Tests should call production code directly.
Application-level tests needing more source files should declare those sources
and dependencies in tests.pro; shared source lists can move into .pri files
when needed. Keep application startup and packaging out of the test target.
GitHub CI
.github/workflows/continuous.yml builds and runs this target on Linux (Qt 5),
macOS (Qt 6), and Windows x64 (Qt 6 with MSVC 2022), on pull requests to master,
pushes to master, and manual runs. JUnit reports are uploaded as artifacts,
including on test failure. Adding a test does not require changing the workflow
or main.cpp.
The Windows job uses nmake and a single release configuration. To reproduce its
commands in an x64 MSVC developer command prompt with Qt on PATH:
mkdir build\tests
cd build\tests
qmake ..\..\tests\tests.pro -spec win32-msvc CONFIG+=release CONFIG-=debug CONFIG-=debug_and_release
nmake /NOLOGO
nmake /NOLOGO check "TESTARGS=-o test-results.xml,junitxml -o -,txt"