如何将dojo / doh测试迁​​移到实习生

时间:2013-11-25 08:12:14

标签: dojo intern

我有很多dojo / doh单元测试,我想迁移到实习生/柴。是否有迁移指南或甚至可以帮助我的转换器?

由于

1 个答案:

答案 0 :(得分:3)

没有转换器可以自动将测试从DOH迁移到实习生,但如果这是您有兴趣创建的,请打开一张新的增强票,因为我们希望有一个。

也没有迁移指南,但几乎在所有情况下,路径都相当简单。

对于断言:

doh.t(value, message)assert.isTrue(value, message)
doh.f(value, message)assert.isFalse(value, message)
doh.e(ErrorType, context, fnName, args, message)assert.throws(lang.hitch(context, fnName, arg1, argN), ErrorType, regExp, message)
doh.is(expected, actual, message)assert.deepEqual(actual, expected, message)
doh.isNot(expected, actual, message)assert.notDeepEqual(actual, expected, message)

(柴有many more assertion types而不是DOH)

对于异步测试:

new doh.Deferredthis.async(timeout)(来自测试功能)
doh.Deferred#getTestErrback(callback)InternDeferred#rejectOnError(callback)
doh.Deferred#getTestCallback(callback)InternDeferred#callback(callback)

用于注册测试:

doh.registerTestType→创建一个新的测试界面(例如tddbdd等)并从您的套房中访问它 doh.register→使用tdd,bdd或对象接口来注册套件和测试。理论上,你可以编写一个模拟doh.register的新测试界面。

doh.register确实是我生命中使用过的最糟糕的API。几乎每一个参数都可以接受多个不同的东西,因此很难清楚地解释大多数这些测试的迁移路径。一些签名,如{ runTest, setUp, tearDown },没有直接的类比,因为在实习生设置和拆解功能是(正确)每套房,而不是每次测试。

所有这些示例都假设registerSuiteintern!object模块的标识符。

doh.register(groupId, [
  function testA() {},
  function testB() {}
], setupFn, teardownFn);

变为

registerSuite({
  name: groupId,
  setup: setupFn,
  teardown: teardownFn,
  testA: function () {},
  testB: function () {}
});

doh.register(groupId, function testFn() {});

变为

registerSuite({ name: groupId, testFn: function () {} });

doh.register(groupId, {
  setUp: setupFn,
  tearDown: teardownFn,
  runTest: testFn,
  name: 'myTest'
});

没有完全映射到Intern模型,因此根据意图成为几个不同的东西之一。

作为一个小套件:

registerSuite({
  name: groupId,
  myTest: {
    setup: setupFn,
    teardown: teardownFn,
    '': testFn
  }
});

作为测试:

registerSuite({
  name: groupId,
  myTest: function () {
    setupFn();
    try {
      testFn();
    }
    finally {
      teardownFn();
    }
  }
});

也可能有其他选择。

doh.runGroup→使用suites参数运行特定套件
doh.togglePaused→使用this.async()控制测试中的流量
doh.pause→使用this.async()控制测试中的流量
doh.run→使用this.async()控制测试中的流量

显然,实习生有许多来自DOH的附加功能,以及与大多数其他测试环境相匹配的不同概念模型,因此一旦掌握了它,它应该更强大,更容易使用。