Skip to content
广告 · 本站推荐广告

测试与验证

部署完成后,建议按照本指南逐步测试各项功能,确保 OpenClaw 正常运行。

快速验证

一键运行所有基础验证:

bash
# 运行完整的系统健康检查
openclaw doctor

# 仅检查特定模块
openclaw doctor --check models
openclaw doctor --check channels
openclaw doctor --check automation

部署后必做

每次部署或升级后,建议至少运行一次 openclaw doctor 确保所有组件正常工作。

测试模式(Dry Run)

OpenClaw 支持测试模式,所有操作只模拟执行,不会产生实际影响:

bash
# 以测试模式启动(不连接真实通道和模型)
openclaw start --dry-run

# 测试模式下发送消息(不会调用模型 API)
openclaw test send --message "你好,这是一条测试消息"

# 测试模式下执行自动化任务
openclaw automation trigger --name "daily-report" --dry-run

测试模式说明

测试模式下:

  • 模型调用会返回模拟响应(Mock Response),不消耗 Token
  • 通道消息不会真正发送
  • 数据库操作会使用临时数据库
  • 自动化任务只记录日志不执行实际动作

模型测试

连接测试

bash
# 测试所有已配置的模型
openclaw models test

# 测试特定模型提供商
openclaw models test --provider deepseek
openclaw models test --provider openai

# 详细输出(包含延迟、Token 计数等)
openclaw models test --provider deepseek --verbose

预期输出示例:

✅ deepseek-chat     | 延迟: 856ms  | 首 Token: 342ms | 状态: 正常
✅ deepseek-reasoner | 延迟: 1203ms | 首 Token: 567ms | 状态: 正常
❌ gpt-4o            | 错误: 连接超时 (可能需要代理)

模型功能测试

bash
# 测试模型基本对话能力
openclaw models test --provider deepseek --prompt "请用一句话介绍你自己"

# 测试模型的 Streaming(流式输出)
openclaw models test --provider deepseek --stream

# 测试模型的 Function Calling(函数调用)能力
openclaw models test --provider deepseek --function-calling

通道测试

连接状态检查

bash
# 查看所有通道状态
openclaw channels status

# 深度探测通道连通性(发送测试心跳)
openclaw channels status --probe

发送测试消息

bash
# 向企业微信发送测试消息
openclaw channels test --name wecom --message "OpenClaw 测试消息"
bash
# 向钉钉发送测试消息
openclaw channels test --name dingtalk --message "OpenClaw 测试消息"
bash
# 向飞书发送测试消息
openclaw channels test --name feishu --message "OpenClaw 测试消息"
bash
# 向 Telegram 发送测试消息
openclaw channels test --name telegram --chat-id <CHAT_ID> --message "OpenClaw test message"

端到端通道测试

bash
# 完整的端到端测试:发送消息 → Agent 处理 → 模型调用 → 返回响应
openclaw channels test --name wecom --e2e --message "今天天气怎么样?"

端到端测试会消耗 Token

端到端测试会实际调用模型 API,产生 Token 消耗。如需免费测试,请使用 --dry-run 参数。

自动化任务测试

手动触发 Cron 任务

bash
# 列出所有自动化任务
openclaw automation list

# 手动触发特定任务(真实执行)
openclaw automation trigger --name "daily-report"

# 模拟触发(仅输出日志,不执行)
openclaw automation trigger --name "daily-report" --dry-run

Webhook 测试

bash
# 测试 webhook 端点是否可达
openclaw automation test-webhook --url http://localhost:7681/api/hooks/my-hook

# 发送模拟 webhook 请求
curl -X POST http://localhost:7681/api/hooks/my-hook \
  -H "Content-Type: application/json" \
  -d '{"action": "test", "data": {"key": "value"}}'

集成测试

运行 OpenClaw 内置的集成测试套件(Integration Test Suite):

bash
# 运行所有集成测试
openclaw test integration

# 运行特定模块的集成测试
openclaw test integration --module gateway
openclaw test integration --module agent
openclaw test integration --module channels

# 生成测试报告
openclaw test integration --report --output test-report.html

性能基准测试(Benchmark)

bash
# 运行标准性能基准测试
openclaw benchmark

# 自定义测试参数
openclaw benchmark \
  --concurrent 10 \
  --requests 100 \
  --model deepseek-chat

基准测试结果参考:

指标2C4G 服务器4C8G 服务器8C16G 服务器
并发请求5-1015-3050+
平均响应时间3-5s2-4s1-3s
每分钟处理请求20-4050-100150+
内存占用300-500MB400-800MB500MB-1.5GB

性能优化建议

如果基准测试结果不理想,可参考以下优化措施:

  • 启用响应缓存(Response Cache)
  • 使用更快的模型(如 DeepSeek V3 Turbo)
  • 增加服务器资源或启用水平扩展(Horizontal Scaling)
  • 优化 System Prompt 长度,减少 Token 消耗

自动化测试脚本

创建自定义测试脚本用于持续验证:

bash
#!/bin/bash
# test-openclaw.sh - OpenClaw 健康检查脚本

echo "=== OpenClaw 健康检查 ==="

# 1. 检查服务状态
openclaw status || { echo "❌ 服务未运行"; exit 1; }

# 2. 测试模型连接
openclaw models test || { echo "❌ 模型连接异常"; exit 1; }

# 3. 测试通道连接
openclaw channels status --probe || { echo "❌ 通道连接异常"; exit 1; }

echo "✅ 所有检查通过"

可将此脚本加入 crontab(定时任务),实现定期自动化验证。

基于MIT协议开源 | 内容翻译自 官方文档,同步更新