混淆嵌套测试套件和规范的执行顺序 [英] confuse about the execution order of nested testing suite and specs
问题描述
全部:
我刚刚开始关于Jasmine的第二天研究,有一个关于exe命令的问题我想弄清楚:
此示例来自Jasmine 2.0简介:
Jasmine 2.0简介
describe(Asynchronous specs,function(){
var value;
beforeEach(函数(完成){
setTimeout(function(){
value = 0;
done();
},1);
});
it(应该支持异步执行测试准备和期望,函数(完成){
value ++;
expect(value).toBeGreaterThan(0);
done();
});
describe(long asynchronous specs,function(){
var originalTimeout;
beforeEach(function(){
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
它(需要很长时间),函数(完成){
setTimeout(function(){
done();
},9000);
});
afterEach(function(){
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
});
});
我试过阅读源代码,但这让我更加困惑,我甚至混淆了我做的哪一部分不明白.... ToT
任何人都可以简单地解释一下茉莉花在遇到之前描述了什么,以及它如何运行以及它是如何运行的?
谢谢
describe
就像一个测试范围,它用于确定在_All,afterAll,beforeEach和afterEach必须执行之前的哪个它
s,它也可以用来简单地分类你的测试因为它有点像章节,带有标题。
第一个 beforeEach
在每个之前执行
在第一个描述
(以及 describe
孩子) 。
第一个 it
可以在没有done参数的情况下编写,因为它只包含同步操作。
然后 beforeEach
inchild describe
在每个测试用例内部执行,然后 it
在里面,最后是 afterEach
,仅在孩子描述
中的每个 it
之后执行。
总结一下,在你的例子中,函数按以下顺序执行:
beforeEach1> it1> beforeEach1> beforeEach2> it2> afterEach
当你传递done参数时,jasmine等待它的执行以继续下一个测试用例(它
)。正如您在上一个案例中所看到的,jasmine必须等待9000ms才能执行 done()
:默认情况下,在5000ms后执行jasmine超时,这就是我们将其更改为10000的原因。 / p>
我希望很清楚,如果还不够,请随时询问详情:)
All:
I just start the second day study about Jasmine, there is one question about exe order I want to figure out:
This example is from Jasmine 2.0 introduction: Jasmine 2.0 Introduction
describe("Asynchronous specs", function() {
var value;
beforeEach(function(done) {
setTimeout(function() {
value = 0;
done();
}, 1);
});
it("should support async execution of test preparation and expectations", function(done) {
value++;
expect(value).toBeGreaterThan(0);
done();
});
describe("long asynchronous specs", function() {
var originalTimeout;
beforeEach(function() {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
it("takes a long time", function(done) {
setTimeout(function() {
done();
}, 9000);
});
afterEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
});
});
I tried reading the source, but it only makes me more confused that I even confuse which part I do not understand....ToT
Could anyone just brief explain what does jasmine do when it meet describe beforeEach and it, and how it runs t?
Thanks
describe
is like a "test-scope" and it's used to determine on which it
s beforeAll, afterAll, beforeEach and afterEach has to execute, it can also be used simply to categorize your tests because it's a bit like a "chapter", with a title.
The first beforeEach
is executed before every it
in the first describe
(and the describe
children).
The first it
could be written without the done parameter since it contains only synchronous operations.
Then beforeEach
in the "child" describe
is executed before each test case inside, then the it
inside, and finally the afterEach
, is only executed after each it
inside the child describe
.
To sum up, In your exemple the functions are executed in this order :
beforeEach1 > it1 > beforeEach1 > beforeEach2 > it2 > afterEach
When you pass the done parameter, jasmine "waits" it's execution to proceed to the next test case (it
). As you can see in the last case, jasmine has to wait 9000ms to execute done()
: by default, jasmine timeouts after 5000ms, that's why we change it to 10000.
I hope it was clear, if it wasn't enough, feel free to ask for details :)
这篇关于混淆嵌套测试套件和规范的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!