需要使用从数据库中检索的值自动执行测试。同样,需要对一组数据运行相同的测试。
我使用Jest Testing框架,必须使用它。test()来测试数据。问题是测试文件首先检查我要传递给它的数组.test(),最初它是空的。请检查随附的代码。
import "jest";
describe('Document Training test suit', function(this:any){
let docTrainingPage: DocumentTraining;
let driver: any;
let valuesArray:Array<any>=[];
var i=0;
beforeAll(async()=>{
const driver = await new ConfigBrowser();
this.driver = driver;
docTrainingPage = new DocumentTraining(this.driver);
await docTrainingPage.connectToDB();
valuesArray = await docTrainingPage.retrieveValues();//Retrieve value from database
});
describe('Should not save the document', async() => {
it.each(valuesArray )('Should NOT savedocuments with INVALID values',async() => {
const A= JSON.stringify(valuesArray[i].AAA);
const B= JSON.stringify(valuesArray[i].BBB);
const C= JSON.stringify(valuesArray[i].CCC);
const D= JSON.stringify(valuesArray[i].DDD);
const E= JSON.stringify(valuesArray[i].EEE);
await docTrainingPage.enterValues(A, B, C, D, E);
const testResult = await docTrainingPage.verifyValidDocTrainingSuccessful();
expect(testResult).toBeTruthy();
i++;
});
})
afterAll(()=>{
docTrainingPage.endConnection();
setTimeout(() => process.exit(), 1000)
});
})
我尝试调试此代码。首先将其转到 beforeAll 。但是然后转到 it 并检查是否存在任何有效的测试。此时,该阵列尚未加载。
错误
●测试套件无法运行
Your test suite must contain at least one test.