本目录包含了灾害去除系统的完整端到端测试套件,用于验证除虫、除草、浇水等功能的正确性。
Land/
├── DisasterRemovalBaseTest.php # 测试基类,提供通用方法
├── PesticideHandlerTest.php # 除虫Handler测试
├── WeedicideHandlerTest.php # 除草Handler测试
├── WateringHandlerTest.php # 浇水Handler测试
├── DisasterRemovalTestSuite.php # 综合测试套件
└── README.md # 本文档
TestConfig.php - 集中管理所有测试配置和环境变量设置测试环境变量:
# 在 .env 文件中添加
UNITTEST_URL=http://localhost:8000
# 运行所有测试
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --all
# 只运行除虫测试
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --pesticide
# 只运行除草测试
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --weedicide
# 只运行浇水测试
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --watering
# 运行完整测试套件
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --suite
# 查看测试配置
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --config
# 查看帮助
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --help
# 运行单个测试类
php artisan test app/Module/AppGame/Tests/Land/PesticideHandlerTest.php
# 运行特定测试方法
php artisan test app/Module/AppGame/Tests/Land/PesticideHandlerTest.php --filter testPesticideSuccess
# 运行所有灾害去除测试
php artisan test app/Module/AppGame/Tests/Land/
'user_id' => 1,
'password' => 'test123456',
'username' => 'test_user'
测试基类,提供:
除虫功能测试,包含:
testPesticideSuccess() - 成功除虫testPesticideWithInvalidItem() - 无效物品测试testPesticideOnOtherUserLand() - 权限测试testPesticideProbability() - 概率机制测试除草功能测试,包含:
testWeedicideSuccess() - 成功除草testWeedicideWithWrongItemType() - 错误物品类型测试testConcurrentWeedicideRequests() - 并发请求测试浇水功能测试,包含:
testWateringSuccess() - 成功浇水testRepeatedWateringOnSameLand() - 重复操作测试testWateringPerformance() - 性能测试综合测试套件,提供:
可以通过修改 TestConfig.php 来自定义测试配置:
// 修改测试用户
public const TEST_USER = [
'user_id' => 2, // 改为其他用户ID
'password' => 'your_password',
'username' => 'your_username'
];
// 修改测试物品
public const TEST_ITEMS = [
'pesticide' => [
'item_id' => 201, // 改为实际的除虫剂ID
'name' => '超级除虫剂',
'numeric_attributes' => [
'fram_pesticide_rate' => 95 // 改为95%成功率
]
]
];
测试会输出详细的调试信息,包括:
连接失败
UNITTEST_URL 环境变量验证失败
概率测试不稳定
测试过程中的错误会记录到 Laravel 日志中:
tail -f storage/logs/laravel.log
TestConfig.php 中添加新的配置DisasterRemovalTestSuite.php 中集成新测试TestConfig.php 中的配置DisasterRemovalBaseTest这些测试可以集成到 CI/CD 流程中:
# GitHub Actions 示例
- name: Run Disaster Removal Tests
run: |
php app/Module/AppGame/Tests/run_disaster_removal_tests.php --all