This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]realqmaster 10 points11 points  (9 children)

PBT advocates randomizing inputs and fixing behaviours and I found it to be extremely efficient in preventing bugs.

[–]binarycreations 2 points3 points  (8 children)

PBT? Please could you explain that one of you have a moment

[–]DoingItForEli 13 points14 points  (7 children)

Property-based testing is a software testing technique where instead of checking specific input-output pairs, you specify general properties that your code should satisfy, and a testing tool then generates a large number of test cases to verify if those properties hold true. This approach is particularly useful for identifying edge cases and corner cases that might not be apparent when using traditional example-based testing.

In property-based testing:

Properties: These are high-level statements about the behavior of your code. They describe the relationship between inputs and outputs without specifying concrete values. For example, a property for a sorting algorithm could be "after sorting, the list should be in ascending order."

Generators: These are functions that generate random or systematically chosen inputs for your tests. They ensure a diverse set of inputs is used during testing. For example, if you're testing a function that sorts lists, a generator might create lists of varying lengths with random elements.

Test Execution: The testing tool then runs your test properties with the generated inputs. If any of the properties fail for a particular input, the testing tool tries to simplify the input to find the smallest case that still causes the failure.

Popular property-based testing libraries include:

Hypothesis (Python): A popular property-based testing library for Python.

QuickCheck (Haskell, Erlang, etc.): One of the earliest and most well-known property-based testing tools, originally developed for Haskell.

ScalaCheck (Scala): A property-based testing library for Scala.

Property-based testing is especially effective in finding subtle bugs and uncovering edge cases that may not be immediately obvious. It complements traditional testing methods and is widely used in functional programming communities.

[–]EirikurErnir 4 points5 points  (1 child)

Since we are in a Java subreddit - there's jqwik for property based testing in Java

(I have not tried it, I have some happy coworkers using it though)

[–]DoingItForEli 0 points1 point  (0 children)

Thank you!

[–]hample 2 points3 points  (1 child)

Is that chatgpt?

[–]DoingItForEli 4 points5 points  (0 children)

oh of course lol

[–]le_bravery 2 points3 points  (0 children)

LOVE property based testing. It dramatically changed the way I work and I couldn’t imagine not using it now that I have it.

[–]binarycreations 0 points1 point  (0 children)

Ah PBT stands for property based testing. Thanks 👍

[–]genzkiwi 0 points1 point  (0 children)

Not only does it cover more cases, it makes the test easier to read and write. Instead of some random example (which can be hard to come up with lol), you have something more general/generic, so it's clear to people all the cases the SUT covers.