aissia/docs/03-implementation/testing-strategy.md
StillHammer ba42b6d9c7 Update CDC with hybrid architecture (WarFactory + multi-target)
- Add hybrid deployment modes: local_dev (MVP) and production_pwa (optional)
- Integrate WarFactory engine reuse with hot-reload 0.4ms
- Define multi-target compilation strategy (DLL/SO/WASM)
- Detail both deployment modes with cost analysis
- Add progressive roadmap: Phase 1 (local), Phase 2 (POC WASM), Phase 3 (cloud)
- Budget clarified: $10-20/mois (local) vs $13-25/mois (cloud)
- Document open questions for technical validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-27 11:49:09 +08:00

214 lines
5.4 KiB
Markdown

# Testing Strategy - Warfactory
**Philosophy** : Testing optimisé pour développement Claude Code avec modules autonomes
## Points 42-44 : Testing & Validation Strategy
### Point 42 : Unit Tests Intégrés (`#ifdef TESTING`)
**Validation autonome intégrée aux modules :**
```cpp
class TankModule : public IModule {
json process(const json& input) override {
// Core tank logic
auto result = processTankBehavior(input);
#ifdef TESTING
// Validation autonome intégrée
validateInputs(input);
validateState();
validateOutputs(result);
#endif
return result;
}
#ifdef TESTING
void runSelfTests() {
// Tests unitaires intégrés au module
testMovement();
testTargeting();
testCombat();
}
private:
void validateInputs(const json& input) {
assert(input.contains("position"));
assert(input.contains("target"));
assert(input["health"].get<float>() >= 0.0f);
}
void validateState() {
assert(currentHealth >= 0.0f);
assert(position.isValid());
assert(ammunition >= 0);
}
void validateOutputs(const json& output) {
assert(output.contains("status"));
assert(output.contains("position"));
assert(output.contains("actions"));
}
#endif
};
```
**Build integration :**
```cmake
# Debug builds enable testing
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(tank PRIVATE TESTING)
endif()
# Test executable
add_executable(tank-test tests/tank_test.cpp src/TankModule.cpp)
target_compile_definitions(tank-test PRIVATE TESTING)
```
### Point 43 : Standalone Testing
**Test modules sans engine complet :**
```cpp
// tests/tank_test.cpp
#include "../src/TankModule.h"
int main() {
TankModule tank;
// Initialize with test config
json config = {
{"health", 100},
{"ammunition", 50},
{"position", {10, 20}}
};
tank.initialize(config);
// Run self-tests
#ifdef TESTING
tank.runSelfTests();
#endif
// Test specific behaviors
json input = {
{"command", "move"},
{"target_position", {15, 25}},
{"health", 100}
};
auto result = tank.process(input);
// Verify output
assert(result["status"] == "moving");
assert(result.contains("position"));
std::cout << "✅ All tank tests passed!" << std::endl;
return 0;
}
```
**Execution autonome :**
```bash
cd modules/tank/
cmake . && make tank-test
./tank-test # Exécute tests sans infrastructure
```
### Point 44 : Testing Strategy AI-Optimized
**Philosophy Claude Code-friendly :**
#### Simple Tests Philosophy
- **No complex infrastructure** : Tests sans setup lourd
- **Minimal dependencies** : JSON in/out uniquement
- **Quick feedback** : <5 secondes pour iteration loops Claude
- **Readable by AI** : Code test compréhensible par IA
#### Module Isolation Testing
```cpp
// ✅ GOOD - Simple, isolated test
void testTankMovement() {
TankModule tank;
json input = {{"command", "move"}, {"target", {10, 10}}};
auto result = tank.process(input);
assert(result["status"] == "moving");
}
// ❌ BAD - Complex infrastructure required
void testTankInCompleteGameWorld() {
GameEngine engine;
MapSystem map;
NetworkManager network;
// 100+ lines setup...
}
```
#### AI Development Workflow
```bash
# Claude Code workflow optimized
1. Edit module → Save
2. Run tests → Instant feedback
3. Iterate → 5-second cycles
# Traditional workflow (avoid)
1. Edit code → Rebuild entire project → Setup test environment → Run tests → 5-10 minutes
```
#### Testing Patterns Claude-Friendly
**Input/Output Testing :**
```cpp
struct TestCase {
std::string name;
json input;
json expected_output;
};
std::vector<TestCase> tankTests = {
{"movement", {{"cmd", "move"}}, {{"status", "moving"}}},
{"combat", {{"cmd", "fire"}}, {{"status", "firing"}}},
{"damaged", {{"health", 10}}, {{"status", "critical"}}}
};
void runAllTests() {
for(auto& test : tankTests) {
auto result = tank.process(test.input);
assert(result == test.expected_output);
std::cout << "✅ " << test.name << " passed" << std::endl;
}
}
```
**Configuration-Driven Testing :**
```json
// tests/tank_test_config.json
{
"test_cases": [
{
"name": "basic_movement",
"input": {"command": "move", "target": [10, 10]},
"expected": {"status": "moving", "eta": 5}
},
{
"name": "low_health_behavior",
"input": {"health": 15, "command": "attack"},
"expected": {"status": "retreating"}
}
]
}
```
## Architecture Benefits
**Development Velocity :**
- **5-second iteration** : Edit Test Feedback
- **Claude optimization** : IA comprend tests facilement
- **Zero infrastructure** : Pas setup complexe
- **Parallel development** : Multiple modules testés simultanément
**Quality Assurance :**
- **Module isolation** : Bugs localisés, pas cascade
- **Autonomous validation** : Modules self-validate via `#ifdef TESTING`
- **Quick regression detection** : Tests rapides détectent régressions
- **AI-readable failures** : Error messages clairs pour Claude Code