Skip to content

Commit a5a3810

Browse files
committed
refactor: classify tests into unit/integration/infer tiers
- Unit tests (BUILD_TESTS=ON, default): types, framework, domain, libs - Integration tests (BUILD_INTEGRATION_TESTS=OFF): TestAppShellIntegration, dsfw-widgets-test - Infer tests (*_BUILD_TESTS=OFF): TestGame, TestRmvpe, TestAudioUtil - Default build now only compiles unit tests (~20 targets fewer)
1 parent 5e27c4e commit a5a3810

3 files changed

Lines changed: 43 additions & 17 deletions

File tree

src/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
option(BUILD_TESTS "Build all test targets" ON)
1+
option(BUILD_TESTS "Build unit test targets" ON)
22

3+
# Infer tests require ONNX models and audio files — off by default
34
if (NOT BUILD_TESTS)
45
set(GAME_INFER_BUILD_TESTS OFF CACHE BOOL "" FORCE)
56
set(SOME_INFER_BUILD_TESTS OFF CACHE BOOL "" FORCE)
67
set(RMVPE_INFER_BUILD_TESTS OFF CACHE BOOL "" FORCE)
78
set(AUDIO_UTIL_BUILD_TESTS OFF CACHE BOOL "" FORCE)
9+
else()
10+
# Default infer tests to OFF even when BUILD_TESTS=ON
11+
# Enable individually: -DGAME_INFER_BUILD_TESTS=ON etc.
12+
if(NOT DEFINED CACHE{GAME_INFER_BUILD_TESTS})
13+
set(GAME_INFER_BUILD_TESTS OFF CACHE BOOL "Build TestGame (requires GAME model)" FORCE)
14+
endif()
15+
if(NOT DEFINED CACHE{SOME_INFER_BUILD_TESTS})
16+
set(SOME_INFER_BUILD_TESTS OFF CACHE BOOL "Build TestSome (requires SOME model)" FORCE)
17+
endif()
18+
if(NOT DEFINED CACHE{RMVPE_INFER_BUILD_TESTS})
19+
set(RMVPE_INFER_BUILD_TESTS OFF CACHE BOOL "Build TestRmvpe (requires RMVPE model)" FORCE)
20+
endif()
21+
if(NOT DEFINED CACHE{AUDIO_UTIL_BUILD_TESTS})
22+
set(AUDIO_UTIL_BUILD_TESTS OFF CACHE BOOL "Build TestAudioUtil" FORCE)
23+
endif()
824
endif ()
925

1026
find_package(QT NAMES Qt6 COMPONENTS Core Gui Widgets Svg Network REQUIRED)

src/tests/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
include(CTest)
66

7+
# ── Infer tests (controlled by per-library options) ──────────────────────────
78
if (TARGET TestGame)
89
add_test(NAME TestGame COMMAND TestGame)
910
endif()
@@ -20,8 +21,14 @@ if (TARGET TestAudioUtil)
2021
add_test(NAME TestAudioUtil COMMAND TestAudioUtil)
2122
endif()
2223

24+
# ── Unit tests (always built when BUILD_TESTS=ON) ────────────────────────────
25+
add_subdirectory(types)
2326
add_subdirectory(framework)
2427
add_subdirectory(domain)
25-
add_subdirectory(widgets)
2628
add_subdirectory(libs)
27-
add_subdirectory(types)
29+
30+
# ── Integration tests (require QApplication / UI, off by default) ────────────
31+
option(BUILD_INTEGRATION_TESTS "Build integration and widget tests (require GUI)" OFF)
32+
if(BUILD_INTEGRATION_TESTS)
33+
add_subdirectory(widgets)
34+
endif()

src/tests/framework/CMakeLists.txt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED)
22

33
set(CMAKE_AUTOMOC ON)
44

5+
# ── Unit tests (pure logic, no QApplication needed) ──────────────────────────
56
set(DSFW_TESTS
67
TestResult
78
TestJsonHelper
@@ -38,18 +39,20 @@ foreach(test_name ${DOMAIN_TESTS})
3839
add_test(NAME ${test_name} COMMAND ${test_name})
3940
endforeach()
4041

41-
# Integration tests (require QApplication / UI components)
42-
set(DSFW_INTEGRATION_TESTS
43-
TestAppShellIntegration
44-
)
45-
46-
foreach(test_name ${DSFW_INTEGRATION_TESTS})
47-
add_executable(${test_name} ${test_name}.cpp)
48-
target_link_libraries(${test_name} PRIVATE
49-
dsfw-ui-core
50-
dsfw-widgets
51-
Qt${QT_VERSION_MAJOR}::Widgets
52-
Qt${QT_VERSION_MAJOR}::Test
42+
# ── Integration tests (require QApplication / UI components) ─────────────────
43+
if(BUILD_INTEGRATION_TESTS)
44+
set(DSFW_INTEGRATION_TESTS
45+
TestAppShellIntegration
5346
)
54-
add_test(NAME ${test_name} COMMAND ${test_name})
55-
endforeach()
47+
48+
foreach(test_name ${DSFW_INTEGRATION_TESTS})
49+
add_executable(${test_name} ${test_name}.cpp)
50+
target_link_libraries(${test_name} PRIVATE
51+
dsfw-ui-core
52+
dsfw-widgets
53+
Qt${QT_VERSION_MAJOR}::Widgets
54+
Qt${QT_VERSION_MAJOR}::Test
55+
)
56+
add_test(NAME ${test_name} COMMAND ${test_name})
57+
endforeach()
58+
endif()

0 commit comments

Comments
 (0)