0

Recently, I'm quite excited when reading about the idea of property based testing.

But I have 1 question that I still cannot find the answer anywhere:

How can property based testing ensures that it will test the corner cases every time?

To be more specific, let say I'm using ScalaCheck to test my division function:

def divide(a: Int, b: Int): Int

As the test cases will be generated randomly, how can I be sure that ScalaCheck will check the case where b = 0 every time?

Minh Thai
  • 568
  • 6
  • 18

2 Answers2

2

Special cases are often properties of their own. If you try to write a single case that covers b = any integer, then all your properties will end up in one big and complicated test. But you can split the parameter space into multiple chunks e.g.:

  • b = positive integer
  • b = negative integer
  • b = 0

And check them separately.

Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45
2

Some PBT tools will always inject corner cases before generating random ones.

For example, jqwik (for Java) would try 0, 1, -1, Integer.MIN…VALUE and Integer.MAX…VALUE before any random values.

johanneslink
  • 4,877
  • 1
  • 20
  • 37