如果第二次失败,重新运行第一个测试,mocha,javascript
rerun first test if second fails, mocha, javascript
我目前有
describeA();
describeB();
A 和 B 都有 it() 测试。
有没有办法在 describeB() after() 函数中再次调用 describeA 到 运行 如果 B 中任何 "it" 失败?
所以在 describeB 之后的函数中它将有:
after(){
if(haveFailedTests)
// how to call run describeA();
}
您可以覆盖所有单独测试的 it
函数,如下所示:
export function it(test: Function, retryCount: number = 4): (this: ITestCallbackContext, done: MochaDone) => any {
return function() {
for (let index = 0; index < retryCount; index++) {
try {
return test()
} catch (error) {
;(browser as any).logger.info(
`retry number ${index + 1}/${retryCount} for step "${error.message}" on it "${
this.test.title
}" and browser "${(browser.capabilities.browserName || '').toString()}"`
)
}
}
return test()
}
}
这使用打字稿,但基本思想仍然存在,用 try/catch
包装您的函数调用,如果失败则重新运行。
我目前有
describeA();
describeB();
A 和 B 都有 it() 测试。 有没有办法在 describeB() after() 函数中再次调用 describeA 到 运行 如果 B 中任何 "it" 失败? 所以在 describeB 之后的函数中它将有:
after(){
if(haveFailedTests)
// how to call run describeA();
}
您可以覆盖所有单独测试的 it
函数,如下所示:
export function it(test: Function, retryCount: number = 4): (this: ITestCallbackContext, done: MochaDone) => any {
return function() {
for (let index = 0; index < retryCount; index++) {
try {
return test()
} catch (error) {
;(browser as any).logger.info(
`retry number ${index + 1}/${retryCount} for step "${error.message}" on it "${
this.test.title
}" and browser "${(browser.capabilities.browserName || '').toString()}"`
)
}
}
return test()
}
}
这使用打字稿,但基本思想仍然存在,用 try/catch
包装您的函数调用,如果失败则重新运行。