Testing¶
Suite overview¶
QTest-based headless unit suite under tests/. No VTK, no Qt::Widgets, no live backend required.
tests/
CMakeLists.txt # visivo_test_support + VisIVOTests
main.cpp # QCoreApplication + QTest::qExec for each class
TestBackendClient.h # Q_OBJECT test class declaration
test_backendclient.cpp # 14 tests
TestCatalogueParser.h
test_catalogue_parser.cpp # 24 tests
Total: 38 tests.
Build¶
cmake -B build -DBUILD_TESTING=ON # off by default
cmake --build build --target VisIVOTests
ctest --test-dir build -V
# or run directly:
build/tests/VisIVOTests -v2
visivo_test_support static library¶
Compiled once, linked by all test targets.
Contents:
BackendClient.cppDiagnosticsManager.cpp
Dependencies: Qt::Core, Qt::Network only.
Does not pull in Qt::Widgets, VTK, or libwcs.
DiagnosticsManager.cpp uses #include <QCoreApplication> (not <QApplication>) so it compiles without Qt::Widgets.
TestBackendClient (14 tests)¶
All tests use QJsonObject literals — no network calls.
parseMomentResultObject¶
Test |
What it checks |
|---|---|
|
all fields round-trip correctly |
|
|
|
absent fields default to zero/empty |
|
absent |
|
|
parsePvResultObject¶
Test |
What it checks |
|---|---|
|
all fields round-trip |
|
|
|
absent |
|
|
parseNoiseResultObject¶
Test |
What it checks |
|---|---|
|
region coords, channel range |
|
array values with float tolerance |
|
|
|
|
|
absent region → all coords 0 |
Note on parsePv_errorResponse: parsePvResultObject calls result.error.clear() after the positions_arcsec_base64 decode step (missing arcsec positions is non-fatal, and error is reused as a scratch buffer). The test therefore only asserts !r.valid and documents this behaviour.
TestCatalogueParser (24 tests)¶
detectedRedshiftField¶
Test |
Input schema |
Expected result |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detectedDistanceField¶
Test |
Input |
Expected |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
no distance field |
|
comovingDistanceMpc¶
Test |
Input z |
Expected range |
|---|---|---|
|
0.0 |
0.0 exactly |
|
-1.0 |
0.0 exactly |
|
0.1 |
400–460 Mpc |
|
1.0 |
3000–3600 Mpc |
|
0.05, 0.10 |
D(0.10) > D(0.05) (monotonicity) |
entryDistanceMpc¶
Test |
Setup |
Expected |
|---|---|---|
|
|
500.0 |
|
|
400–460 Mpc |
|
no distance/z field |
300.0 |
|
|
750.0 |
|
|
150–280 Mpc |
|
|
300.0 (z=0 → Dc=0 → fallback) |
Adding new tests¶
Create
TestFoo.hwithclass TestFoo : public QObject { Q_OBJECT private slots: … };Create
test_foo.cppwith implementationsAdd both files to
add_executable(VisIVOTests …)intests/CMakeLists.txtAdd
{ TestFoo t; status |= QTest::qExec(&t, argc, argv); }totests/main.cpp
If the new test needs additional source files from src/, add them to visivo_test_support (if they have no Qt::Widgets/VTK dependency) or create a second test support library.