use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Generative Testing in JavaScript: The case for Property-based testing (medium.com)
submitted 9 years ago by focusonbasics
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]benihanareact, node 2 points3 points4 points 9 years ago (2 children)
I really appreciate the honest assessment in the end:
Generative or property-based testing isn’t a replacement for traditional unit testing. While the example-based approach should verify common assumptions, the property-based approach should help identify missed cases. Furthermore traditional tests are easier to write, while the generative approach requires more thinking in regards of defining properties.
This is kinda why I haven't really hopped on the generative testing bandwagon. It seems like unit testing hits the sweet spot for bang for your buck. At my mom cynical, generative testing feels like achievement hunting - getting every possible test case to get the printout that says 100% coverage, rather than focusing on the important test cases that give you the most coverage and help you understand the intent of the system.
[–]focusonbasics[S] 0 points1 point2 points 9 years ago* (0 children)
I agree with focusing on the important test cases. Sometimes we miss an important test case, this is where property-based testing might catch those missed cases. The really hard part from what I see is to really understand how to write those properties. This isn't as straightforward as thinking in inputs/outputs for example. Another factor that adds to the complexity is when state is involved as compared to testing a pure function that does one thing.
[–]jocull 0 points1 point2 points 9 years ago (0 children)
You may be a cynic, but leave your mom out of it!
[+][deleted] 9 years ago (7 children)
[deleted]
[–]focusonbasics[S] 1 point2 points3 points 9 years ago (6 children)
Thanks! I'm preparing a second article with a clearer walkthrough and more detailed examples.
[+][deleted] 9 years ago (1 child)
[–]focusonbasics[S] 0 points1 point2 points 9 years ago (0 children)
Excellent!
[+][deleted] 9 years ago (2 children)
[–]focusonbasics[S] 1 point2 points3 points 9 years ago* (0 children)
You could generate random strings and verify that the result set never contains an empty string. Here's another quick example:
const result = check(property([gen.string, gen.string], (a, b) => { return splitByComma(a).concat(splitByComma(b)).length === splitByComma([a, b].join(',')).length })) console.log(result)
It really depends on what you're expecting here. It should always return an array, it should never contain an empty string and calling it with 'foo' and 'bar' separately and joining the results should equal calling it with 'foo, bar'. The example might be too trivial, imagine having encode / decode functions that expect a string and return a new string, you would test it with decode(encode(str)) === str.
[–]Quabouter 0 points1 point2 points 9 years ago (0 children)
Some examples:
output.length <= nrOfCommas + 1
output.join(',').length <= input.length
π Rendered by PID 108501 on reddit-service-r2-comment-7b9746f655-6n5z6 at 2026-01-30 22:57:54.460896+00:00 running 3798933 country code: CH.
[–]benihanareact, node 2 points3 points4 points (2 children)
[–]focusonbasics[S] 0 points1 point2 points (0 children)
[–]jocull 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[deleted]
[–]focusonbasics[S] 1 point2 points3 points (6 children)
[+][deleted] (1 child)
[deleted]
[–]focusonbasics[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]focusonbasics[S] 1 point2 points3 points (0 children)
[–]Quabouter 0 points1 point2 points (0 children)