扫一扫分享
使用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.assert(fc.property(fc.string(), fc.string(), fc.string(), (a,b,c) => {
// Alternatively: no return statement and direct usage of expect or assert
return contains(a+b+c, b));
});
});
});
仅供个人学习参考/导航指引使用,具体请以第三方网站说明为准,本站不提供任何专业建议。如果地址失效或描述有误,请联系站长反馈~感谢您的理解与支持!
手机预览