Generating Unit Tests: a first look at fast-check

preview_player
Показать описание
Property-based testing is a great way to ensure your tests cover more cases than the usual example-based tests. Fast-check is a pretty great library for doing property-based testing in JavaScript & TypeScript. Here's my first look at it!

Рекомендации по теме
Комментарии
Автор

An interesting concept. Thanks Andrew.

PickleRiiiiiiick
Автор

cool stuff! Wasn't aware of this one!. Just a quick question. Shouldn't you add all those restrictions (e.g. no white-space, no number, etc.) as validations in the code itself instead of in the test? Just wondering...

alessandroferrari
Автор

Awesome video, I really like the way you introduce the subject and the example you use for it. The fact, that errors come incrementally makes it even more powerful.

Regarding the custom arbitraries you suggest in the video, I'd rather recomment.

A faster implementation of no-whitespace like: noWhitespace = => c !== ' '))
The proposed implementation works but internally fast-check will probably generate lots of strings containing just one space and drop them while it could just not generate any string made of empty spaces.

A less extreme not a number arbitrary. Indeed the proposed version drops values such as "123abc" or "a1a"... while they could potentially find bugs. I'd probably do something like:
noWhitespaceNorANumber = noWhitespace.filter(s => !/^[\d\.e-]+$/.test(s))
The proposed approach still drops too much but a bit less than the one proposed by the video.

ndubien
Автор

cool one! you really deserve better views

nourmanhjr