时间
测试时间
许多报告器将显示测试持续时间并标记缓慢的测试(默认值:75ms),如 SPEC 报告器所示:
测试持续时间分为三个级别(如下图所示):
- 快速地: 在 “slow” 阈值一半内运行的测试将以绿色显示持续时间(如果有的话)。
- 普通的: 运行超过阈值一半(但仍在阈值内)的测试将以黄色显示持续时间。
- 慢的: 运行超过阈值的测试将以红色显示持续时间。
要调整 “slow” 的内容,你可以使用 slow() 方法:
describe('something slow', function () {
this.slow(300000); // five minutes
it('should take long enough for me to go make a sandwich', function () {
// ...
});
});
超时
套件级别超时可应用于整个测试 “suites”,或通过 this.timeout(0) 禁用。 这将被所有不覆盖该值的嵌套套件和测试用例继承。
describe('a suite of tests', function () {
this.timeout(500);
it('should take less than 500ms', function (done) {
setTimeout(done, 300);
});
it('should take less than 500ms as well', function (done) {
setTimeout(done, 250);
});
});
TEST-LEVEL
还可以应用特定于测试的超时,或者使用 this.timeout(0) 一起禁用超时:
it('should take less than 500ms', function (done) {
this.timeout(500);
setTimeout(done, 300);
});
HOOK-LEVEL
还可以应用钩子级超时:
describe('a suite of tests', function () {
beforeEach(function (done) {
this.timeout(3000); // A very long environment setup.
setTimeout(done, 2500);
});
});