Search code examples
unit-testingtestingproperty-based-testingjqwik

When to choose Example based testing and property based for Stateful Testing


I'm doing unit testing mostly these days for Android SDK in Android Studio and using Jqwik which is a Property-Based testing tool on the JUnit Platform.

While exploring the different test techniques approach with my seniors, I learned about example-based testing and property-based testing. I want to know when to choose which one.


Solution

  • For me it’s usually not an either-or question, but examples and properties often complement each other. Whereas examples are good starting points for the intended behaviour of the code under test, properties serve to give me sufficient trust in the breadth of functionality and expected behaviour in edge and corner cases.

    There are situations where examples are better replaced by properties, eg when many examples can be translated into a single or just a few properties. Even then I tend to keep some examples, because they are easier to understand.