kards-env/tests/README.md

98 lines
2.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# KARDS Battle System 测试套件
这里包含了KARDS战斗系统的所有测试代码。
## 📁 测试结构
```
tests/
├── unit/ # 单元测试
│ ├── test_unit_type_rules.py # 单位类型战斗规则测试
│ └── test_artillery_simple.py # 火炮攻击测试
├── integration/ # 集成测试
│ ├── test_drag_system.py # 拖拽操作系统测试
│ ├── test_corrected_battlefield.py # 战场系统测试
│ └── test_*.py # 其他集成测试
├── examples/ # 示例测试
│ └── test_readme_example.py # README示例代码测试
└── run_tests.py # 测试运行器
```
## 🚀 运行测试
### 运行所有测试
```bash
# 使用Shell脚本推荐
./run_tests.sh
# 使用Python测试运行器
python3 tests/run_tests.py
```
### 运行特定类型的测试
```bash
# 单元测试
python3 tests/unit/test_unit_type_rules.py
python3 tests/unit/test_artillery_simple.py
# 集成测试
python3 tests/integration/test_drag_system.py
# 示例测试
python3 tests/examples/test_readme_example.py
```
## 📋 测试内容
### 🔧 单元测试
- **test_unit_type_rules.py**: 全面测试各兵种的战斗规则
- 步兵攻击相邻战线规则
- 火炮无视距离和守护,不受反击
- 战斗机保护机制
- 轰炸机不受反击规则
- **test_artillery_simple.py**: 专门测试火炮不受反击机制
### 🔗 集成测试
- **test_drag_system.py**: 测试真实的拖拽操作系统
- 拖拽到空位 = 移动
- 拖拽到敌方 = 攻击
- 指挥点和激活成本管理
- **test_corrected_battlefield.py**: 测试3线战场系统
- 战场布局和控制权
- 单位部署和移动
### 📖 示例测试
- **test_readme_example.py**: 验证README中的示例代码正确工作
## ✅ 测试验证的功能
- ✅ 真实的3条战线布局
- ✅ 两种玩家操作:使用卡牌、拖动单位
- ✅ 拖拽统一移动/攻击操作
- ✅ 指挥点资源管理
- ✅ 激活点数(油费)系统
- ✅ 单位类型特殊规则
- ✅ 战斗伤害和反击计算
- ✅ 前线控制权机制
- ✅ 挤位置移动规则
## 🎯 测试原则
1. **不要防御式编程**: 如果期望没达到就直接报错,不掩盖问题
2. **完整性测试**: 每个功能都要有对应的测试
3. **真实场景**: 测试要模拟真实的游戏使用场景
4. **清晰输出**: 测试结果要清晰显示通过/失败状态
## 🔧 添加新测试
1. 在相应目录创建 `test_*.py` 文件
2. 添加适当的路径设置:
```python
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
```
3. 更新 `run_tests.sh` 包含新测试
4. 确保测试输出清晰的通过/失败信息