编写 A 型框架的测试规范

Dan*_*ang 2 aframe

我对 VR 完全陌生,正在 AFrame 中为一个班级项目开发 VR 太空射击游戏,想知道 AFrame 中是否有 TDD 的任何文档/标准。有人能指出我正确的方向吗?

ngo*_*vin 5

几乎完全使用 A-Frame 组件构建您的应用程序:https://aframe.io/docs/0.4.0/guides/writing-a-component.html

然后测试组件。A-Frame 代码库中的几乎每个组件都有单元测试:https://github.com/aframevr/aframe/tree/master/tests/components

中的组件模板angle还有一个单元测试设置。https://github.com/aframevr/angle/tree/master/templates/componentnpm install -g angle && angle initcomponent对于独立组件)。

测试使用 Karma 启动真实的浏览器并执行代码。它将实体附加到 DOM,附加具有不同属性值的组件,并断言值。一个基本的例子:

suite('foo component', function () {
  var component;
  var el;

  setup(function (done) {
    el = entityFactory();
    el.addEventListener('componentinitialized', function (evt) {
      if (evt.detail.name !== 'foo') { return; }
      component = el.components.foo;
      done();
    });
    el.setAttribute('foo', {});
  });

  suite('update', function () {
    test('bar', function () {
      el.setAttribute('foo', 'bar', 10);
      assert.equal(component.baz, 10);  // Assert something.
    });
  });
});
Run Code Online (Sandbox Code Playgroud)