Your Python code is almost entirely untested.
Vložit
- čas přidán 27. 08. 2024
- Sign up for 1-on-1 coaching at dougmercer.dev
-----------------------------------------
Property-based testing is an alternative to example-based testing where tests verify that properties of the output are satisfied given randomly generated input. This randomized approach allows us to more thoroughly test against a broad range of input and can detect hard-to-find bugs better than example-based testing.
In this video, we discuss the motivation behind property-based testing. We continue by exploring the Hypothesis package, a Python package that makes data generation and property testing easy. Finally, we show an end-to-end example property-based unit test and provide some parting recommendations for applying property testing to your own code.
Hypothesis Documentation: hypothesis.rea...
Hypothesis Ghostwriter (for some broadly useful examples of property tests): hypothesis.rea...
#python #unittest
From Reddit to CZcams and From CZcams to subscription ✅
"Dont write tests. Write test writers"
Cool, this is like QuickCheck for Haskell. I like the Ghostwriter thing for common properties, that's something QuickCheck lacks.
…in fact, after searching some more, they’re definitely related! The hypothesis author has some blog posts about the design of QuickCheck and why they think it’s bad.
What’s the song playing in the back? Love the bassline
The song is "I'm the Man" by Jason Szklarek. I got it from StoryBlocks. (www.storyblocks.com/audio/stock/im-the-man-bo3a62xwpkg5dchtz.html)
The bass line is really fun!
This is really awesome , do you think the hypothesis can support objects or dicts?
I'm more interested in integration testing then unit testing , regardless this is all super useful , thanks alot for being so awesome
Yeah! Hypothesis can generate pretty much anything you can dream up.
Here's the built in strategy for dictionaries, hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.dictionaries
If you ever need to build up something exotic (or make data that is kind of jointly dependent on each other, you can use hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.composite . Composite strategy is basically:
1. Write a function decorated by st.composite with "draw" as the first argument (injected by the decorator)
2. Write a function consisting of other strategies. Use draw(strat) to sample from the sub strategies.
Note: composite strategies can become slow. You may need to adjust your hypothesis settings to avoid hitting annoying "Deadline" health checks)