mysql - 使用 Jest 进行数据驱动测试
问题描述
需要使用从数据库中检索的值来自动化测试。此外,需要使用一组数据运行相同的测试。
我使用 Jest 测试框架并且必须使用 it.test() 来测试数据。问题是测试文件首先检查我传递给 it.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。但随后它会去检查是否有任何有效的测试。此时,数组未加载。
错误
● 测试套件无法运行
Your test suite must contain at least one test.
解决方案
推荐阅读
- r - 当我尝试使用随机森林模型进行预测时,为什么会出现错误?
- haskell - 不能满足-package yesod-1.6.0
- python - 如何在下拉列表中同时显示值和文本?
- python - 在 Python 3 中接受用户输入
- vba - 如何使用 VBA 宏将剪贴板拆分为 Microsoft Word 中的多个字符串?
- r - 使用填充时突出显示一个条并用数字标记每个条
- python - django - 'ModelName' 对象不可迭代
- java - 无法使用具有 2 个 spring 上下文的存储库和服务
- c# - Networkstream 多线程和传输数据
- php - 如何在 Eloquent ORM 中禁止插入、更新和删除模型