All Projects → dubzzz → Fast Check

dubzzz / Fast Check

Licence: mit
Property based testing framework for JavaScript (like QuickCheck) written in TypeScript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Fast Check

ava-fast-check
Property based testing for AVA based on fast-check
Stars: ✭ 44 (-98.31%)
Mutual labels:  unit-testing, quickcheck, property-based-testing, generative-testing
Rapid
Rapid is a Go library for property-based testing that supports state machine ("stateful" or "model-based") testing and fully automatic test case minimization ("shrinking")
Stars: ✭ 213 (-91.82%)
Mutual labels:  fuzzing, property-based-testing, quickcheck
Deepstate
A unit test-like interface for fuzzing and symbolic execution
Stars: ✭ 603 (-76.84%)
Mutual labels:  unit-testing, fuzzing, property-based-testing
kitimat
A library for generative, property-based testing in TypeScript and Jest.
Stars: ✭ 68 (-97.39%)
Mutual labels:  quickcheck, property-based-testing, generative-testing
fuzz-rest-api
Derive property based testing fast-check into a fuzzer for REST APIs
Stars: ✭ 38 (-98.54%)
Mutual labels:  quickcheck, property-based-testing, fuzzing
Jqf
JQF + Zest: Coverage-guided semantic fuzzing for Java.
Stars: ✭ 340 (-86.94%)
Mutual labels:  fuzzing, property-based-testing, quickcheck
Hypothesis
Hypothesis is a powerful, flexible, and easy to use library for property-based testing.
Stars: ✭ 5,571 (+113.94%)
Mutual labels:  fuzzing, property-based-testing
Haskell Hedgehog
Release with confidence, state-of-the-art property testing for Haskell.
Stars: ✭ 584 (-77.57%)
Mutual labels:  property-based-testing, quickcheck
Stream data
Data generation and property-based testing for Elixir. 🔮
Stars: ✭ 597 (-77.07%)
Mutual labels:  property-based-testing, quickcheck
Enzyme Matchers
Jasmine/Jest assertions for enzyme
Stars: ✭ 881 (-66.17%)
Mutual labels:  unit-testing, tdd
Expecto
A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Stars: ✭ 495 (-80.99%)
Mutual labels:  unit-testing, property-based-testing
Quixote
CSS unit and integration testing
Stars: ✭ 788 (-69.74%)
Mutual labels:  unit-testing, tdd
Quick check.js
A JS implementation of quick_check
Stars: ✭ 48 (-98.16%)
Mutual labels:  property-based-testing, quickcheck
Jasmine Matchers
Write Beautiful Specs with Custom Matchers for Jest and Jasmine
Stars: ✭ 552 (-78.8%)
Mutual labels:  unit-testing, tdd
Ut
UT: C++20 μ(micro)/Unit Testing Framework
Stars: ✭ 507 (-80.53%)
Mutual labels:  unit-testing, tdd
Tasty
Modern and extensible testing framework for Haskell
Stars: ✭ 499 (-80.84%)
Mutual labels:  unit-testing, quickcheck
Junit Quickcheck
Property-based testing, JUnit-style
Stars: ✭ 821 (-68.47%)
Mutual labels:  property-based-testing, quickcheck
Autoparams
Arbitrary test data generator for parameterized tests in Java inspired by AutoFixture.
Stars: ✭ 77 (-97.04%)
Mutual labels:  unit-testing, tdd
Sinon
Test spies, stubs and mocks for JavaScript.
Stars: ✭ 8,828 (+239.02%)
Mutual labels:  unit-testing, tdd
Swiftcheck
QuickCheck for Swift
Stars: ✭ 1,319 (-49.35%)
Mutual labels:  property-based-testing, quickcheck

fast-check logo

Property based testing framework for JavaScript/TypeScript

Build Status npm version monthly downloads

Coverage Status (unit tests) Package quality Snyk Package quality

PRs Welcome License Twitter

Getting started

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:

Why should I migrate to fast-check?

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:

  • Types: strong and up-to-date types - thanks to TypeScript
  • Extendable: easy 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
  • Extendable: kind of flatMap-operation called chain [more] - able to bind the output of an arbitrary as input of another one while keeping the shrink working
  • Extendable: precondition checks with fc.pre(...) [more] - filtering invalid entries can be done directly inside the check function if needed
  • Smart: ability to shrink on fc.oneof [more] - surprisingly some frameworks don't
  • Smart: biased by default [more] - by default it generates both small and large values, making it easier to dig into counterexamples without having to tweak a size parameter manually
  • Debug: verbose mode [more] - easier troubleshooting with verbose mode enabled
  • Debug: replay directly on the minimal counterexample [more] - no need to replay the whole sequence, you get directly the counterexample
  • Debug: custom examples in addition of generated ones [more] - no need to duplicate the code to play the property on custom examples
  • Debug: logger per predicate run [more] - simplify your troubleshoot with fc.context and its logging feature
  • Unique: model based approach [more][article] - use the power of property based testing to test UI, APIs or state machines
  • Unique: detect race conditions in your code [more] - shuffle the way your promises and async calls resolve using the power of property based testing to detect races
  • Unique: simplify user definable corner cases [more] - simplify bug resolution by asking fast-check if it can find an even simpler corner case

For more details, refer to the documentation in the links above.

Compatibility

Here are the minimal requirements to use fast-check properly without any polyfills:

fast-check node ECMAScript version TypeScript (optional)
2.x ≥8(1) ES2017 ≥3.2
1.x ≥0.12(1) ES3 ≥3.0

(1) Except for features that cannot be polyfilled - such as 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.

ReScript bindings

Bindings to use fast-check in ReScript are available in package rescript-fast-check. They are maintained by @TheSpyder as an external project.

Issues found by fast-check in famous packages

fast-check has been able to find some unexpected behaviour among famous npm packages. Here are some of the errors detected using fast-check:

jest

Issue detected: toStrictEqual fails to distinguish 0 from 5e-324 [more]

Code example: expect(0).toStrictEqual(5e-324) succeeds

js-yaml

Issue detected: enabling !!int: binary style when dumping negative integers produces invalid content [more]

Code example: yaml.dump({toto: -10}, {styles:{'!!int':'binary'}}) produces toto: 0b-1010 not toto: -0b1010

query-string

Issue detected: enabling the bracket setting when exporting arrays containing null values produces an invalid output for the parser [more]

Code example:

m.stringify({bar: ['a', null, 'b']}, {arrayFormat: 'bracket'}) //=> "bar[]=a&bar&bar[]=b"
m.parse('bar[]=a&bar&bar[]=b', {arrayFormat: 'bracket'})       //=> {bar: [null, 'b']}

MORE: Issues detected thanks to fast-check

Credits

Code Contributors

This project would not be the same without them 💖 - Become one of them

Backers

Thank you to all our backers! 🙏 [Become a backer] and help us sustain our community.

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].