Spaces:
Sleeping
Sleeping
๐งช Test Scripts
This directory contains all test scripts for the RTS Web version.
๐ Available Tests
1. test.sh - Main Test Suite
./test.sh
Purpose: Complete test suite for all game features
Coverage:
- Server connection
- Game initialization
- Unit creation and control
- Building construction
- Resource management
- Combat system
- AI behavior
- UI rendering
Usage:
- Ensure server is running (
cd .. && python start.py) - Execute from web/ directory:
./tests/test.sh - Review output for any failures
2. test_features.sh - Feature-Specific Tests
./test_features.sh
Purpose: Test specific game features individually
Coverage:
- Fog of War
- Unit production
- Building placement
- Resource gathering
- Combat mechanics
- Superweapon system
Usage:
- Run after major feature additions
- Use for regression testing
- Verify specific functionality
3. test_harvester_ai.py - Harvester AI Tests
python test_harvester_ai.py
Purpose: Comprehensive harvester AI testing
Coverage:
- Pathfinding to Tiberium
- Resource collection
- Return to refinery
- Avoiding obstacles
- Manual control override
- State transitions
Dependencies:
requests
websocket-client
Usage:
- Detailed harvester behavior testing
- AI logic verification
- Performance benchmarking
Output:
- Step-by-step AI decisions
- State transition logs
- Performance metrics
4. docker-test.sh - Docker Testing
./docker-test.sh
Purpose: Test Docker deployment
Coverage:
- Docker build process
- Container startup
- Server accessibility
- WebSocket connections
- Production readiness
Usage:
- Pre-deployment testing
- Docker configuration validation
- CI/CD pipeline integration
Requirements:
- Docker installed
- Docker daemon running
- Port 8000 available
5. test_mcp_server.py - MCP Server Tests
python test_mcp_server.py
Purpose: Test MCP server functionality
Coverage:
- MCP server import
- Server instance creation
- Server initialization
Usage:
- Run to verify MCP server functionality
- Use for regression testing of MCP integration
Output:
- Import success/failure
- Instance creation success/failure
- Initialization success/failure
๐ Quick Start
Basic Test Run
cd /home/luigi/rts/web
python start.py & # Start server
./tests/test.sh # Run tests
Harvester AI Test
cd /home/luigi/rts/web
python start.py &
python tests/test_harvester_ai.py
MCP Server Test
cd /home/luigi/rts/web
python tests/test_mcp_server.py
Docker Test
cd /home/luigi/rts/web
./tests/docker-test.sh
๐ Test Coverage
| Test Script | Features Tested | Execution Time | Automation |
|---|---|---|---|
| test.sh | All core features | ~2 min | โ Full |
| test_features.sh | Specific features | ~3 min | โ Full |
| test_harvester_ai.py | Harvester AI only | ~1 min | โ Full |
| docker-test.sh | Docker deployment | ~5 min | โ Full |
| test_mcp_server.py | MCP server functionality | ~10s | โ Full |
๐ง Test Configuration
Environment Variables
# Server URL (default: http://localhost:8000)
export TEST_SERVER_URL="http://localhost:8000"
# WebSocket URL (default: ws://localhost:8000/ws)
export TEST_WS_URL="ws://localhost:8000/ws"
# Test timeout (default: 30s)
export TEST_TIMEOUT=30
Prerequisites
Server running:
cd /home/luigi/rts/web python start.pyDependencies installed:
pip install -r ../requirements.txtPorts available:
- 8000 (HTTP/WebSocket)
- 8080 (if testing multiple instances)
๐ Troubleshooting
Test Failures
Connection Errors:
# Check if server is running
curl http://localhost:8000/health
# Check WebSocket
wscat -c ws://localhost:8000/ws
Harvester AI Tests Fail:
# Verify AI module loaded
curl http://localhost:8000/api/game/state | grep harvester
# Check logs
tail -f server.log
Docker Tests Fail:
# Check Docker status
docker ps
docker logs rts-web
# Rebuild if needed
docker build -t rts-web .
docker run -p 8000:8000 rts-web
๐ Test Results
Expected Output
โ Successful Run:
[PASS] Server connection
[PASS] Game initialization
[PASS] Unit creation
[PASS] Building construction
[PASS] Combat system
[PASS] AI behavior
All tests passed!
โ Failed Run:
[FAIL] Unit creation - Timeout
[FAIL] Combat system - Assertion error
2 tests failed, 4 passed
๐ Continuous Integration
GitHub Actions Example
name: RTS Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Tests
run: |
cd web
python start.py &
sleep 5
./tests/test.sh
๐ Adding New Tests
Test Script Template
#!/bin/bash
# Description: Test [feature name]
echo "Testing [feature]..."
# Setup
SERVER_URL=${TEST_SERVER_URL:-http://localhost:8000}
# Test logic
curl -f $SERVER_URL/api/[endpoint] || exit 1
echo "[PASS] [Feature] test"
Python Test Template
import requests
import time
def test_feature():
"""Test [feature name]"""
response = requests.get('http://localhost:8000/api/endpoint')
assert response.status_code == 200
print("[PASS] Feature test")
if __name__ == '__main__':
test_feature()
๐ Recent Updates
- โ All test scripts organized in dedicated directory
- โ Complete documentation for each test
- โ Docker testing added
- โ Harvester AI comprehensive tests
- โ CI/CD integration examples
For main project README: See ../README.md
For documentation: See ../docs/
๐ Support
Issues with tests? Check:
- Server logs:
server.log - Documentation:
../docs/ - Troubleshooting guide:
../docs/TROUBLESHOOTING.md(if exists)