Mocha - 测试跳过的设置消息(原因)
Mocha - Setting message (reason) for test skip
是否可以设置一条消息(提及原因)为什么跳过特定测试,以便在记者中使用。
describe('xxx', function() {
checkToSkip(1)("test1", function() {\*test goes here*\});
checkToSkip(4)("test2", function() {\*test goes here*\});
});
function checkToSkip(now) {
return now > 3 ? it : xit;
//return now > 3 ? it : it.skip;
}
此处'test1'将被跳过为'checkToSkip'returns'xit'(或it.skip)。是否可以给记者发消息说明跳过测试的原因?类似下面的内容(或任何其他可能的方式)。
checkToSkip(4)("test2", function() { \ test goes here}, "My Skip message!!!!" );
注意:我在 webdriverIO 中使用 mocha。
谢谢。
我只是稍微修改了 checkToSkip
函数并使用 Pending Tests 而不是 skip()
。
function checkToSkip(now, title, testCallable) {
if (now > 3) {
it(title, testCallable);
} else {
it(title+"#My Skip message!#");
}
}
然后像这样使用它:
describe('xxx', function() {
checkToSkip(1, "test1", function() {\*test goes here*\});
});
可以在跳过之前在测试中修改测试标题本身:
it('My cool test', async function() {
if (this.response.status !== 201) {
this._runnable.title += ' - Skipped with reason: wrong response code'
this.skip()
}
expect(this.response.data).to.have.property('mycoolproperty')
})
也可以将检查形式化并将其移至外部函数:
function skipIf(that, condition, reason){
if (condition) {
that._runnable.title += ` - Skipped with reason: ${reason}`
that.skip()
}
}
因此测试将如下所示:
it('My cool test', async function() {
skipIf(this, this.response.status !==201, 'Wrong response status')
expect(this.response.data).to.have.property('mycoolproperty')
})
是否可以设置一条消息(提及原因)为什么跳过特定测试,以便在记者中使用。
describe('xxx', function() {
checkToSkip(1)("test1", function() {\*test goes here*\});
checkToSkip(4)("test2", function() {\*test goes here*\});
});
function checkToSkip(now) {
return now > 3 ? it : xit;
//return now > 3 ? it : it.skip;
}
此处'test1'将被跳过为'checkToSkip'returns'xit'(或it.skip)。是否可以给记者发消息说明跳过测试的原因?类似下面的内容(或任何其他可能的方式)。
checkToSkip(4)("test2", function() { \ test goes here}, "My Skip message!!!!" );
注意:我在 webdriverIO 中使用 mocha。
谢谢。
我只是稍微修改了 checkToSkip
函数并使用 Pending Tests 而不是 skip()
。
function checkToSkip(now, title, testCallable) {
if (now > 3) {
it(title, testCallable);
} else {
it(title+"#My Skip message!#");
}
}
然后像这样使用它:
describe('xxx', function() {
checkToSkip(1, "test1", function() {\*test goes here*\});
});
可以在跳过之前在测试中修改测试标题本身:
it('My cool test', async function() {
if (this.response.status !== 201) {
this._runnable.title += ' - Skipped with reason: wrong response code'
this.skip()
}
expect(this.response.data).to.have.property('mycoolproperty')
})
也可以将检查形式化并将其移至外部函数:
function skipIf(that, condition, reason){
if (condition) {
that._runnable.title += ` - Skipped with reason: ${reason}`
that.skip()
}
}
因此测试将如下所示:
it('My cool test', async function() {
skipIf(this, this.response.status !==201, 'Wrong response status')
expect(this.response.data).to.have.property('mycoolproperty')
})