fast-check 介绍
使用TypeScript编写的基于JavaScript的基于 属性 的测试框架(如QuickCheck) ,基于 属性 的测试框架检查 属性 的真实性。 属性 是这样的语句:对于所有(x,y,...),例如precondition(x,y,...)都认为property(x,y,...)为true。
通过以下方式安装模块:
yarn add fast-check --dev或npm install fast-check --save-dev
示例 :
const fc = require('fast-check');
// Code under test
const contains = (text,pattern) => text.indexOf(pattern) >= 0;
// Properties
describe('properties',() => {
// string text always contains itself
it('should always contain itself',() => {
fc.assert(fc.property(fc.string(),text => contains(text,text)));
});
// string a + b + c always contains b,whatever the values of a,b and c
it('should always contain its substrings',fc.string(),(a,b,c) => {
// Alternatively: no return statement and direct usage of expect or assert
return contains(a+b+c,b));
});
});
});
GitHub: https://github.com/dubzzz/fast-check
网站描述: 用TypeScript编写基于Property 的JavaScript测试框架
fast-check官方网站
官方网站:
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。