本文介绍了QUnit异步测试,安装和拆卸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一点点帮助理解QUnit internas。
我读的时间源的时间,但我仍然写怪异的测试,当涉及到异步测试。
我理解的异步测试的概念,并停止()和start()方法(和为什么需要他们),但是当我安装和拆卸它们组合起来我得到了很多的weired的情况。

I need a little help understanding QUnit internas.I read its source from time to time, but i'm still writing weird test when it comes to asynchronous tests.I understand the concept of asynchronous tests, and the stop() and start() methods (and why they are needed), but when i combine them with setup and teardown i get a lot of weired situations.

下面是我的测试code:

Here is my Testcode:

use(['Psc.Exception','Psc.Code'], function () {
  module("async", {
    setup: function () {
      console.log('setup');
    }, teardown: function () {
      console.log('teardown');
    }
  });

  asyncTest("test1", function () {
    expect(0);

    console.log('test1');
    start();
  });

  asyncTest("test2", function () {
    expect(0);

     console.log('test2');
     start();
  });

  asyncTest("test3", function () {
    expect(0);

    console.log('test3');
    start();
  });

  asyncTest("test4", function () {
    expect(0);

    console.log('test4');
    start();
  });

  asyncTest("test5", function () {
    expect(0);

    console.log('test5');
    start();
  });
});

Allthough这些asynchron测试,我想我会在控制台中是这样的:

Allthough these are asynchron tests, i thought i would get something like this in the console:

setup
test1
teardown
setup
test2
teardown
setup
test3
teardown
...

因为我以为qunit会叫建立和拆除周围的测试人体的?

because i thought qunit would call setup and teardown around the test bodys?

但我得到的一切混在一起,从申请到洗牌另一种方式提出要求。

but I get everything mixed up, from request to request in another way shuffled.

setup
test1
teardown
setup
setup
setup
setup
test5
teardown
test4
teardown
test3
teardown
test2
teardown

是有人能够解释它一步一步?

is someone able to explain it step by step?

推荐答案

这是一个记录的问题:

其建议QUnit.config.autostart设置为false,异步加载测试时。这是我的情况,因为使用是异步这样做。

its is recommended to set QUnit.config.autostart to false, when loading tests asynchronously. This is my case because "use" is doing it asynchronously.

头看起来是这样的:

QUnit.config.autostart = false;
use(['Psc.Exception','Psc.Code'], function () {

  QUnit.start();
  module("async", {

因此​​,它基本上是这样做的stop()和start(),但加载测试本身。我测试了它和拆卸/安装/测试现在以正确的顺序得到正确执行

So its basically like doing stop() and start() but for loading the tests itself. I tested it and the teardown / setup / test now get correctly executed in the right order

这篇关于QUnit异步测试,安装和拆卸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:06