Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Fast Check | 3,536 | 1,950 | 525 | a day ago | 152 | September 19, 2022 | 22 | mit | TypeScript | |
Property based testing framework for JavaScript (like QuickCheck) written in TypeScript | ||||||||||
Quickcheck | 2,048 | 384 | 724 | 9 days ago | 84 | January 15, 2021 | 40 | unlicense | Rust | |
Automated property based testing for Rust (with shrinking). | ||||||||||
Scalacheck | 1,857 | 137 | 2,258 | 2 days ago | 34 | December 17, 2020 | 59 | bsd-3-clause | Scala | |
Property-based testing for Scala | ||||||||||
Fscheck | 1,020 | 724 | 25 | 5 months ago | 92 | June 01, 2022 | 23 | bsd-3-clause | F# | |
Random Testing for .NET | ||||||||||
Junit Quickcheck | 926 | 193 | 49 | 6 days ago | 44 | November 22, 2020 | 37 | mit | Java | |
Property-based testing, JUnit-style | ||||||||||
Stream_data | 759 | 173 | 24 | 8 days ago | 9 | May 03, 2020 | 13 | Elixir | ||
Data generation and property-based testing for Elixir. 🔮 | ||||||||||
Haskell Hedgehog | 641 | 93 | 13 days ago | 21 | January 30, 2022 | 94 | Haskell | |||
Release with confidence, state-of-the-art property testing for Haskell. | ||||||||||
Tasty | 593 | 16 days ago | 33 | Haskell | ||||||
Modern and extensible testing framework for Haskell | ||||||||||
Jscheck | 569 | 2 years ago | 2 | August 16, 2017 | JavaScript | |||||
A random property testing tool for JavaScript | ||||||||||
Quicktheories | 482 | 65 | 25 | 2 years ago | 11 | March 06, 2019 | 23 | apache-2.0 | Java | |
Property based testing for Java 8 |
Property based testing framework for JavaScript/TypeScript
Hands-on tutorial and definition of Property Based Testing: see tutorial. Or directly try it online on our pre-configured CodeSandbox.
Property based testing frameworks check the truthfulness of properties. A property is a statement like: for all (x, y, ...) such that precondition(x, y, ...) holds predicate(x, y, ...) is true.
Install the module with: yarn add fast-check --dev
or npm install fast-check --save-dev
Example of integration in mocha:
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);
})
);
});
});
In case of failure, the test raises a red flag. Its output should help you to diagnose what went wrong in your implementation. Example with a failing implementation of contain:
1) should always contain its substrings
Error: Property failed after 1 tests (seed: 1527422598337, path: 0:0): ["","",""]
Shrunk 1 time(s)
Got error: Property failed by returning false
Hint: Enable verbose mode in order to have the list of all failing values encountered during the run
Integration with other test frameworks: ava, jasmine, jest, mocha and tape.
More examples: simple examples, fuzzing and against various algorithms.
Useful documentations:
fast-check has initially been designed in an attempt to cope with limitations I encountered while using other property based testing frameworks designed for JavaScript:
map
method to derive existing arbitraries while keeping shrink [more] - some frameworks ask the user to provide both a->b and b->a mappings in order to keep a shrinker
chain
[more] - able to bind the output of an arbitrary as input of another one while keeping the shrink working
fc.pre(...)
[more] - filtering invalid entries can be done directly inside the check function if needed
fc.oneof
[more] - surprisingly some frameworks don't
For more details, refer to the documentation in the links above.
fast-check has been trusted for years by big projects like: jest, jasmine, fp-ts, io-ts, ramda, js-yaml, query-string...
It also proved useful in finding bugs among major open source projects such as jest, query-string... and many others.
Here are the minimal requirements to use fast-check properly without any polyfills:
fast-check | node | ECMAScript version | TypeScript (optional) |
---|---|---|---|
3.x | 8(1) | ES2017 | 4.1(2) |
2.x | 8(1) | ES2017 | 3.2(3) |
1.x | 0.12(1) | ES3 | 3.0(3) |
bigint
-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check.@types/node
to be installed.@types/node
to be installed.Bindings to use fast-check in ReScript are available in package rescript-fast-check. They are maintained by @TheSpyder as an external project.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome! Become one of them
Many individuals and companies offer their financial support to the project, a huge thanks to all of them too
You can also become one of them by contributing via GitHub Sponsors or OpenCollective.