jest的数据驱动测试

kwvwclae  于 2021-06-23  发布在  Mysql
关注(0)|答案(0)|浏览(322)

需要使用从数据库检索的值来自动化测试。同样,同样的测试也需要用一组数据来运行。
我使用jest测试框架,并且必须使用它.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)       
});

})

我试过调试这个代码。在开始的时候它会先发生。但接下来它会去检查是否有任何有效的测试。此时,数组未加载。
错误
● 测试套件无法执行

Your test suite must contain at least one test.

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题