This document provides information about the comprehensive test suite for TowerForge.
The project includes three types of tests prioritized as follows:
- Integration Tests (Highest Priority) - Test interactions between major components
- End-to-End (E2E) Tests (Second Priority) - Test complete workflows
- Unit Tests (Lowest Priority) - Test unique or complex logic only
tests/
├── integration/ # Integration tests
│ ├── test_tower_grid_integration.cpp
│ ├── test_facility_manager_integration.cpp
│ ├── test_ecs_world_integration.cpp
│ ├── test_save_load_integration.cpp
│ ├── test_achievement_manager_integration.cpp
│ └── test_lua_mod_manager_integration.cpp
├── e2e/ # End-to-end tests
│ ├── test_game_initialization_e2e.cpp
│ ├── test_facility_placement_workflow_e2e.cpp
│ └── test_save_load_workflow_e2e.cpp
└── unit/ # Unit tests
├── test_user_preferences_unit.cpp
├── test_command_history_unit.cpp
└── test_accessibility_settings_unit.cpp
Before running tests, ensure you have:
- CMake 3.20 or newer
- A C++20-capable compiler (GCC 10+, Clang 10+, or MSVC 2019+)
- vcpkg installed and bootstrapped
- On Linux: X11 development libraries installed
# On Ubuntu/Debian
sudo apt-get install -y build-essential cmake pkg-config \
libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
libgl1-mesa-dev libglu1-mesa-dev xvfb- Clone and bootstrap vcpkg (if not already done):
git clone https://github.com/microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh # or .bat on Windows- Configure the project with the test CMake preset:
For CLI/Agent builds (recommended to avoid IDE conflicts):
export VCPKG_ROOT=/path/to/vcpkg
cmake --preset cli-testFor IDE builds:
export VCPKG_ROOT=/path/to/vcpkg
cmake --preset test- Build all tests:
For CLI/Agent builds:
cmake --build --preset cli-test-debug --parallel $(nproc)On Windows (cmd.exe):
cmake --build --preset cli-test-debug --parallel %NUMBER_OF_PROCESSORS%For IDE builds:
cmake --build --preset test-debug --parallel $(nproc)Note: The cli-test preset builds to build-cli/cli-test/ to avoid CMake cache conflicts with IDE builds in build/test/.
You can build individual test targets:
cmake --build --preset test-debug --target test_tower_grid_integration
cmake --build --preset test-debug --target test_user_preferences_unit
cmake --build --preset test-debug --target test_game_initialization_e2eFor CLI/Agent builds:
cd build-cli/cli-test/tests
ctest -C Debug --output-on-failureOr run tests in parallel:
cd build-cli/cli-test/tests
ctest -C Debug -j$(nproc) --output-on-failureAlternatively, use the test preset:
ctest --preset cli-test-debugFor IDE builds:
cd build/test/tests
ctest -C Debug --output-on-failureOr use the test preset:
ctest --preset test-debugEach test executable can be run directly:
For CLI/Agent builds:
# From the project root
./build-cli/cli-test/bin/Debug/test_tower_grid_integration
./build-cli/cli-test/bin/Debug/test_facility_manager_integration
./build-cli/cli-test/bin/Debug/test_user_preferences_unitFor IDE builds: For CLI/Agent builds:
cd build-cli/cli-test/tests ctest -C Debug -R ".*_integration" --output-on-failure
cd build-cli/cli-test/tests ctest -C Debug -R ".*_e2e" --output-on-failure
cd build-cli/cli-test/tests ctest -C Debug -R ".*_unit" --output-on-failure
**For IDE builds**:
```bash
# Run only integration tests
./build/test/bin/Debug/test_tower_grid_integration
./build/test/bin/Debug/test_facility_manager_integration
For CLI/Agent builds:
# Run only tests matching a pattern
./build-cli/cli-test/bin/Debug/test_tower_grid_integration --gtest_filter="*FloorExpansion*"
# Run all tests except those matching a pattern
./build-cli/cli-test/bin/Debug/test_tower_grid_integration --gtest_filter="-*Removal*"
# List all tests without running them
./build-cli/cli-test/bin/Debug/test_tower_grid_integration --gtest_list_testsFor IDE builds:
Run only integration tests: cd build/test/tests
Run only E2E tests:
cd build/test/tests
ctest -C Debug -R ".*_e2e" --output-on-failureRun only unit tests:
cd build/test/tests
ctest -C Debug -R ".*_unit" --output-on-failureYou can run specific test cases within a test executable:
# Run only tests matching a pattern
./build/test/bin/Debug/test_tower_grid_integration --gtest_filter="*FloorExpansion*"
# Run all tests except those matching a pattern
./build/test/bin/Debug/test_tower_grid_integration --gtest_filter="-*Removal*"
# List all tests without running them
./build/test/bin/Debug/test_tower_grid_integration --gtest_list_testsIntegration tests verify that multiple components work together correctly:
- TowerGrid Integration: Floor/column management, facility placement, spatial queries
- FacilityManager Integration: Facility creation, placement on grid, removal, maintenance operations
- ECSWorld Integration: ECS initialization, entity creation, subsystem interactions
- SaveLoadManager Integration: Save/load operations, slot management, autosave functionality
- AchievementManager Integration: Achievement tracking, unlocking, progress management
- LuaModManager Integration: Mod loading, custom content registration
E2E tests verify complete workflows from start to finish:
- Game Initialization: Complete game startup sequence, system initialization
- Facility Placement Workflow: Building floors, placing facilities, expanding the tower
- Save/Load Workflow: Saving game state, loading into fresh world, continuing play
Unit tests focus on complex or unique logic:
- UserPreferences: Preferences persistence, validation, state management
- CommandHistory: Undo/redo functionality, command stack management
- AccessibilitySettings: Accessibility configuration and validation
As of the latest build:
- Tests build successfully - All compilation and linking issues resolved
- 10 out of 12 tests passing (83% pass rate)
- 2 tests failing due to save/load implementation bug:
test_save_load_integration: 1 failure - grid state not properly restored after loadingtest_save_load_workflow_e2e: 5 failures - all related to save/load grid state restoration bug
- ✅
test_tower_grid_integration- All 13 tests passing - ✅
test_facility_manager_integration- All tests passing - ✅
test_ecs_world_integration- All 12 tests passing - ✅
test_achievement_manager_integration- All tests passing - ✅
test_lua_mod_manager_integration- All tests passing - ✅
test_game_initialization_e2e- All tests passing - ✅
test_facility_placement_workflow_e2e- All tests passing - ✅
test_user_preferences_unit- All tests passing - ✅
test_command_history_unit- All tests passing - ✅
test_accessibility_settings_unit- All 9 tests passing
- ❌
SaveAndLoadComplexState: Saves 11 occupied cells but loads 0 occupied cells
Root Cause: SaveLoadManager doesn't properly serialize/deserialize grid occupancy state.
All failures have the same root cause as above - grid state not restored after loading:
- ❌
CompleteSaveLoadCycle - ❌
SaveComplexTowerAndReload - ❌
MultipleQuickSaves - ❌
SaveAfterModifyingTower - ❌
ContinuePlayingAfterLoad
Root Cause: Same as test_save_load_integration - SaveLoadManager serialization bug.
The test infrastructure is complete and functional. The 2 failing test suites correctly identify a real implementation bug in save/load grid state serialization. This is not a test structure issue but an actual bug in the production code that needs to be fixed.
Follow this structure for new tests:
#include <gtest/gtest.h>
#include "core/your_component.hpp"
using namespace TowerForge::Core;
class YourComponentTest : public ::testing::Test {
protected:
void SetUp() override {
// Initialize test fixtures
}
void TearDown() override {
// Clean up after tests
}
// Test fixtures
4. Use the appropriate test preset:
- For CLI/Agent: `cmake --preset cli-test`
- For IDE: `cmake --preset test`
5. If you see CMake cache conflicts, ensure you're using the `cli-test` preset (builds to `build-cli/`) to avoid conflicts with IDE builds
TEST_F(YourComponentTest, DescriptiveTestName) {
// Arrange
// Act
// Assert
EXPECT_EQ(actual, expected);
}- One assertion concept per test: Each test should verify one specific behavior
- Clear test names: Use descriptive names that explain what is being tested
- Arrange-Act-Assert: Structure tests with clear setup, execution, and verification
- Clean up resources: Always clean up temporary files, saves, or state
- Independent tests: Tests should not depend on each other
- Meaningful assertions: Use appropriate EXPECT_* macros (EXPECT_EQ, EXPECT_TRUE, etc.)
Tests are automatically run in CI on:
- Push to main or develop branches
- Pull request creation or updates
CI configuration is in .github/workflows/build.yml.
- Ensure vcpkg is properly bootstrapped
- Verify all dependencies are installed
- Check that you're using C++20 compatible compiler
- Use the test preset:
cmake --preset test - Try cleaning and rebuilding:
cmake --build --preset test-debug --clean-first
- Check that all required system libraries are installed (especially on Linux)
- Verify file permissions on test executables
- For save/load tests, ensure write permissions in the test directory
- Run tests in parallel:
ctest -j$(nproc) - Run only necessary tests during development
- Use test filters to focus on relevant tests
For questions or issues with the test suite, please create an issue on the GitHub repository.