在JavaScript测试用例中的所有和AfterAll之前 [英] BeforeAll and AfterAll in javascript test cases
本文介绍了在JavaScript测试用例中的所有和AfterAll之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在所有测试之前做一些事情,之后呢?组织代码的最佳方法是什么?例如:备份一些变量 - >清除它们 - >测试一些东西 - >恢复备份。 'beforeEach'和'afterEach'过于昂贵。谢谢!
I want do something before all tests, then after? What is the best way to organize my code? For example: backup some variables -> clear them -> test something -> restore backups. 'beforeEach' and 'afterEach' are too expencive. Thanks!
推荐答案
一个非常简单的解决方案:
A pretty simple solution:
describe("all o' my tests", function() {
it("setup for all tests", function() {
setItUp();
});
describe("actual test suite", function() {
});
it("tear down for all tests", function() {
cleanItUp();
});
});
这样做的好处是你可以把你的设置/拆解放在任何地方(例如,在开头/嵌套套件的结尾)。
This has the advantage that you can really put your setup/teardown anywhere (eg. at the begining/end of a nested suite).
这篇关于在JavaScript测试用例中的所有和AfterAll之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文