《游戏编辑器技术原理与架构》14.1 编辑器冒烟测试

冒烟用例是一条固定的步骤链:启动、打开项目、放置对象、保存。任何一步失败或超时立即中止,后面的步骤不再执行;报告保留已执行步骤与累计耗时。冒烟不追求覆盖率,只回答编辑器还能不能启动并完成一次基本操作。本节从零实现并真跑 6 条用例,对标 Unity / Unreal / Godot / Cocos Creator 的编辑器冒烟测试。

14.1 编辑器冒烟测试

冒烟用例是一条固定的步骤链:启动、打开项目、放置对象、保存。任何一步失败或超时立即中止,后面的步骤不再执行;报告保留已执行步骤与累计耗时。冒烟不追求覆盖率,只回答编辑器还能不能启动并完成一次基本操作。

本章与站内既有内容的分工

主题站内既有内容本节做什么
自动化基础《架构内核》 第 14 章内核提供命令回放;本节做面向编辑器的冒烟链
质量门禁本卷 13.313.3 消费结果;本节产生冒烟结论
全卷脉络本卷目录本节是自动化测试章的第一块

从零实现:编辑器冒烟测试

运行器顺序消费步骤,每一步都记入已执行列表并累加耗时;结果不是 pass 时立即返回失败报告,stoppedAt 标明停在哪一步。全部通过则返回成功报告;空步骤链视为通过,因为没有失败发生。

本例由调用方注入步骤,检查顺序、首个失败和报告字段。真实编辑器的启动、窗口就绪和进程超时需要外层驱动。Godot 的 --headless 适合不依赖画面的命令行任务,界面交互应另设测试。 Godot 命令行文档

flowchart TD
    A["准备独立项目与步骤"] --> B["执行下一步并记录结果"]
    B --> C{"步骤通过?"}
    C -->|否| D["报告首个失败"]
    C -->|是| E{"仍有步骤?"}
    E -->|是| B
    E -->|否| F["返回成功报告"]

对标 Unity / Unreal / Godot / Cocos:编辑器冒烟测试

引擎机制取舍
UnityUnity Test Framework编辑器测试与冒烟用例
UnrealAutomation Spec编辑器自动化与冒烟测试
GodotGUT / 自定义脚本社区测试框架
Cocos Creator自动化测试扩展编辑器内自动化用例
helio(本节)SmokeRunner步骤链 + 中止 + 耗时

可运行产物:6 条用例

下面是 src/smoke-runner.ts,层级 L1,完整可编译。运行命令 node --test test/14-1-editor-smoke-test.test.ts:

// file: src/smoke-runner.ts
// tier: L1
// verify: node --test test/14-1-editor-smoke-test.test.ts
//
// 卷四(第十四章):编辑器自动化测试——冒烟测试。
// 冒烟用例是一条固定的步骤链:启动、打开项目、放置对象、保存。任何一步
// 失败或超时立即中止,后面的步骤不再执行;报告保留已执行步骤与累计耗时。
// 冒烟不追求覆盖率,只回答「编辑器还能不能启动并完成一次基本操作」。

export type StepResult = 'pass' | 'fail' | 'timeout';

export interface SmokeStep {
  name: string;
  result: StepResult;
  ms: number;
}

export interface SmokeReport {
  passed: boolean;
  executed: SmokeStep[];
  totalMs: number;
  stoppedAt?: string;
}

export class SmokeRunner {
  run(steps: SmokeStep[]): SmokeReport {
    const executed: SmokeStep[] = [];
    let totalMs = 0;
    for (const step of steps) {
      executed.push({ ...step });
      totalMs += step.ms;
      if (step.result !== 'pass') {
        return { passed: false, executed, totalMs, stoppedAt: step.name };
      }
    }
    return { passed: true, executed, totalMs };
  }
}

超时与失败用同一个中止路径,因为它们对「编辑器是否可用」的结论相同;区别只在报告里保留的结果标记。已执行步骤返回副本,调用方可以安全地渲染报告,不会影响运行器持有的输入。

下面是 test/14-1-editor-smoke-test.test.ts,层级 L1:

// file: test/14-1-editor-smoke-test.test.ts
// tier: L1
// verify: node --test test/14-1-editor-smoke-test.test.ts
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { SmokeRunner } from '../src/smoke-runner.ts';

const step = (name: string, result: 'pass' | 'fail' | 'timeout' = 'pass', ms = 10) => ({
  name,
  result,
  ms,
});

test('全部步骤通过', () => {
  const report = new SmokeRunner().run([step('boot'), step('open'), step('save')]);
  assert.equal(report.passed, true);
  assert.deepEqual(report.executed.map((s) => s.name), ['boot', 'open', 'save']);
  assert.equal(report.totalMs, 30);
});

test('失败步骤中止后续执行', () => {
  const report = new SmokeRunner().run([step('boot'), step('open', 'fail'), step('save')]);
  assert.equal(report.passed, false);
  assert.equal(report.stoppedAt, 'open');
  assert.deepEqual(report.executed.map((s) => s.name), ['boot', 'open']);
});

test('超时视同失败并记录耗时', () => {
  const report = new SmokeRunner().run([step('boot', 'timeout', 5000)]);
  assert.equal(report.passed, false);
  assert.equal(report.stoppedAt, 'boot');
  assert.equal(report.totalMs, 5000);
});

test('耗时累计到中止处', () => {
  const report = new SmokeRunner().run([step('a', 'pass', 5), step('b', 'fail', 7)]);
  assert.equal(report.totalMs, 12);
});

test('空步骤链视为通过', () => {
  const report = new SmokeRunner().run([]);
  assert.equal(report.passed, true);
  assert.deepEqual(report.executed, []);
  assert.equal(report.stoppedAt, undefined);
});

test('结果按执行顺序保存副本', () => {
  const steps = [step('a'), step('b')];
  const report = new SmokeRunner().run(steps);
  report.executed[0].name = 'mutated';
  assert.equal(steps[0].name, 'a');
});

本机实测(Node v26.5.0,node --test test/14-1-editor-smoke-test.test.ts):tests 6 · pass 6 · fail 0,耗时约 40 ms。

前两条钉通过链与失败中止;第三条钉超时;第四条钉耗时;后两条钉空链与结果副本。

小结

  • 冒烟测试是固定步骤链,不追求覆盖率。
  • 失败与超时都立即中止后续步骤。
  • 报告保留已执行步骤、累计耗时与中止位置。
  • 结果返回副本,调用方可安全展示。

阅读导航:上一节:13.3 发布检查与质量门禁 · 下一节:14.2 命令回放与截图回归 。

继续阅读

探索更多技术文章

浏览归档,发现更多关于系统设计、工具链和工程实践的内容。

全部文章 返回首页

「books」更多文章

  1. 《大规模分布式计算深入解析·向量数据库与 AI 检索内核》 · 目录与学习路径(45 篇)
  2. 《大规模分布式计算深入解析》15.3 自研向量引擎:可执行骨架与工程缺口
  3. 《大规模分布式计算深入解析》14.1 Milvus:组件架构、段管理与检索链路