TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Effective Property-Based Testing

87 pointsby mullrover 4 years ago

14 comments

spockzover 4 years ago
I would like to make a shout out to quickcheck (Haskell, <a href="https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;QuickCheck" rel="nofollow">https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;QuickCheck</a>) as it was my first introduction to property based testing and has since let me to use property based testing everywhere in the last 10 years. Then there is scalacheck (<a href="https:&#x2F;&#x2F;www.scalacheck.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.scalacheck.org&#x2F;</a>). Both let you write your own generators and are quite good at shrinking down to minimal use cases.<p>The suggestion elsewhere in this thread to decrease the number of iterations during normal testing and crank it up during nightlies is also good.<p>The only thing I’m still missing from the libraries is a convenient mechanism of remembering previously failing generated inputs and use them as a static list of testcases next to the at runtime generated ones like a regression test of sorts.<p>Edit: typos
评论 #26020707 未加载
评论 #26019221 未加载
评论 #26022009 未加载
mristinover 4 years ago
If you use Python and want to infer test strategies from contracts, you might want to check out this library of mine: [1].<p>There are also plugins for IDEs (Pycharm, VS Code and vim), which can be quite helpful during the development.<p>[1]: <a href="http:&#x2F;&#x2F;github.com&#x2F;mristin&#x2F;icontract-hypothesis" rel="nofollow">http:&#x2F;&#x2F;github.com&#x2F;mristin&#x2F;icontract-hypothesis</a>
rckover 4 years ago
This is a great set of ideas for using property-based testing. I&#x27;ve found it useful to think of code in terms of invariants and contracts, and property-based testing lets me express those very directly in code. No other testing method comes close.
Smaug123over 4 years ago
Brilliant article.<p>If I were to add just one thing to the list: metatest. Write a test that asserts that your generated test cases are &quot;sufficiently comprehensive&quot;, for whatever value of &quot;sufficiently&quot; you need. In an impure language, this is as easy as having the generator contain a mutable counter for &quot;number of test cases meeting X condition&quot; for whatever conditions you&#x27;re interested in. For example, say your property is &quot;A iff B&quot;. You might want to fail the test if fewer than 10% of the generated cases actually had A or B hold. (And then, of course, make sure your generators are such that - say - A and B hold 50% of the time; you want an astronomically small chance of random metatest failure.)<p>(I did a brief intro to this in the Metatesting section of a talk I did two years ago: <a href="https:&#x2F;&#x2F;github.com&#x2F;Smaug123&#x2F;talks&#x2F;blob&#x2F;master&#x2F;DogeConf2019&#x2F;DogeConfPBT.pdf" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Smaug123&#x2F;talks&#x2F;blob&#x2F;master&#x2F;DogeConf2019&#x2F;D...</a> . On rereading it now, I see there&#x27;s a typo on the &quot;bounded even integers&quot; slide, where the final `someInts` should read `evenIntegers`.)
评论 #26072251 未加载
mathwover 4 years ago
I&#x27;ve been trying to push property-based testing at work but there&#x27;s not a load of enthusiasm showing. I guess it&#x27;s in part because we work in C# and the best option appears to be FsCheck, which is very inconsistently documented between its F#-native and C#-accessible APIs.<p>I think there&#x27;s a strong argument with FsCheck to write all your proptest code in F# just to take advantage of the vastly better generator syntax, but that&#x27;s a hard sell for a team who mostly don&#x27;t know F# and aren&#x27;t convinced proptests are much better anyway. Writing the generators in C# seemed really incredibly tedious. I did start to get the hang of identifying properties to test though. Once you&#x27;re past the mechanics of &quot;how does this work&quot; that can become much easier.<p>A load road to travel here, but I kind of gave myself a remit to improve software quality and I do think we need to be looking at this kind of testing to help.<p>Where do people who are using it find that it offers the most value? I keep feeling that we could really solidify some of our bespoke parsing and serialisation code using this kind of tech.
评论 #26034406 未加载
hinkleyover 4 years ago
Hypothesis:<p>Property Based Testing is Monte Carlo simulation for model checking.
评论 #26072262 未加载
lowercase1over 4 years ago
This is a good overview of property based testing but the mentions of Cucumber threw me off.<p>In my job Cucumber seems to add little more than just commenting and sequencing functions, tasks that are better suited to your programming language of choice, while adding overhead and complexity.<p>What am I missing?
评论 #26020627 未加载
the_gastropodover 4 years ago
Property testing is awesome, but it does significantly slow down test suites. Are there any standard practices for striking a balance of getting the added confidence&#x2F;safety of using property tests without introducing large delays into your CI pipeline?
评论 #26018251 未加载
评论 #26018385 未加载
评论 #26018902 未加载
评论 #26018278 未加载
spionover 4 years ago
For JS and TypeScript, the best property testing library I&#x27;ve encountered so far is fast-check <a href="https:&#x2F;&#x2F;github.com&#x2F;dubzzz&#x2F;fast-check" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dubzzz&#x2F;fast-check</a>
delightfulover 4 years ago
Does anyone have any thoughts on the graphic showing the spectrum of testing options listed in the article (or additional resources that cover at a high-level this topic of understanding range of testing options)?<p>link to the graphic for ease of reference:<p><a href="https:&#x2F;&#x2F;blog.auxon.io&#x2F;images&#x2F;posts&#x2F;effective-property-based-testing-1.png" rel="nofollow">https:&#x2F;&#x2F;blog.auxon.io&#x2F;images&#x2F;posts&#x2F;effective-property-based-...</a>
mavelikaraover 4 years ago
When you first start on PBT, the first hurdle is finding good properties of your system to test. I found this article [1] to be a great overview to get started.<p>[1]: <a href="https:&#x2F;&#x2F;fsharpforfunandprofit.com&#x2F;posts&#x2F;property-based-testing-2&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fsharpforfunandprofit.com&#x2F;posts&#x2F;property-based-testi...</a>
leeuw01over 4 years ago
Auxon also looks like an interesting company.
评论 #26018736 未加载
pfdietzover 4 years ago
Turning off shrinking makes little sense to me. If tests are passing there&#x27;s nothing to shrink. If you are bombarded with so many failures you can&#x27;t afford to shrink them then more testing is pointless.
评论 #26022039 未加载
mekatronixover 4 years ago
These are great tips. Thanks.