在mocha框架(使用javascript)中,有没有一种方法可以重用来自描述块的特定测试用例(it块)
我对mocha框架相当陌生,我想知道我们是否可以重用来自特定描述块的测试用例在mocha框架(使用javascript)中,有没有一种方法可以重用来自描述块的特定测试用例(it块),javascript,mocha.js,spectron,Javascript,Mocha.js,Spectron,我对mocha框架相当陌生,我想知道我们是否可以重用来自特定描述块的测试用例 For example //Test.js describe("Reuse code here" , function(){ it("Want to reuse this test case " , function () { //do some test here . }) }) //test1.js in test1.js can I access the it
For example
//Test.js
describe("Reuse code here" , function(){
it("Want to reuse this test case " , function () {
//do some test here .
})
})
//test1.js
in test1.js can I access the it block of test.js
您是否可以将传递给it的函数重构为它自己的函数 例如 比如说
//Test.js
describe("Reuse code here" , function(){
it("Want to reuse this test case " , customReusableFunction)
})
function customReusableFunction(){
// do stuff here
}
嗨,谢谢你的回复。我添加重构函数作为测试步骤,并完全重用整个测试用例。我不想在每个测试套件中复制粘贴相同的测试用例。我只是想通过重用测试用例本身来减少代码的重量,而不仅仅是functions.test suite1.js test suite2.js test suite3.js test suite4.js,每个套件都位于不同的文件中。我想在不同的文件中定义登录测试用例,并在所有4个测试套件中使用此测试用例(it块)。