Questions tagged [property-based-testing]

111 questions
16
votes
2 answers

What to use property testing for

I'd like to know what is the property testing aiming for, what is it's sweet point, where it should be used. Let' have an example function that I want to test: f :: [Integer] -> [Integer] This function, f, takes a list of numbers and will square…
coubeatczech
  • 5,892
  • 7
  • 43
  • 71
13
votes
2 answers

Property based testing in PHP?

In various more functional based languages there are tools (like Quickcheck) which allow for property based testing. How would I go about property based testing in PHP? I would like to be able to specify the in and output properties of a PHP method,…
Ward Bekker
  • 5,926
  • 8
  • 35
  • 60
13
votes
3 answers

Difficulty thinking of properties for FsCheck

I've managed to get xUnit working on my little sample assembly. Now I want to see if I can grok FsCheck too. My problem is that I'm stumped when it comes to defining test properties for my functions. Maybe I've just not got a good sample set of…
Benjol
  • 57,639
  • 51
  • 180
  • 252
11
votes
3 answers

Generating list of lists with custom value limitations with Hypothesis

The Story: Currently, I have a function-under-test that expects a list of lists of integers with the following rules: number of sublists (let's call it N) can be from 1 to 50 number of values inside sublists is the same for all sublists…
alecxe
  • 414,977
  • 106
  • 935
  • 1,083
11
votes
2 answers

What is the difference between Agitar and Quickcheck property based testing?

A number of years ago a Java testing tool called Agitar was popular. It appeared to do something like property based testing. Nowadays - property based testing based on Haskell's Quickcheck is popular. There are a number of ports to Java…
hawkeye
  • 31,052
  • 27
  • 133
  • 271
8
votes
3 answers

Is it a good or a bad thing that a suite of quickcheck tests match the implementations?

I'm trying to get started with Haskell's QuickCheck, and while I am familiar with the concepts behind the testing methodology, this is the first time I am trying to put it to use on a project that goes beyond testing stuff like reverse . reverse ==…
8
votes
2 answers

What is the difference between Property Based Testing and Mutation testing?

My context for this question is in Python. Hypothesis Testing Library (i.e. Property Based Testing): https://hypothesis.readthedocs.io/en/latest/ Mutation Testing Library: https://github.com/sixty-north/cosmic-ray
7
votes
1 answer

Difference between generating random input through 'Gen' or through 'forAll' in Hedgehog

Suppose, I want to test the following associativity property for Sum with the help of hedgehog library in Haskell: a <> (b <> c) ≡ (a <> b) <> c I have actually two ways to generate random input. 1. Generate all in Gen (using Gen's Applicative and…
7
votes
1 answer

Safest way to generate random GADT with Hedgehog (or any other property-based testing framework)

I have GADT like this one: data TType a where TInt :: TType Int TBool :: TType Bool I want to have a function like this one: genTType :: Gen (TType a) Which can generate random constructor of TType type. I can do this simply by creating…
Shersh
  • 8,297
  • 3
  • 27
  • 54
7
votes
1 answer

Skipping falsifying examples in Hypothesis

The Story: I'm currently in the process of unit-testing a function using hypothesis and a custom generation strategy trying to find a specific input to "break" my current solution. Here is how my test looks like: from solution import answer #…
alecxe
  • 414,977
  • 106
  • 935
  • 1,083
6
votes
1 answer

How to use FsCheck to generate random numbers as input for property-based testing

I thought it's time to try out FsCheck but it proves tougher than I thought. There's a lot of documentation on Arb, generators and so on, but there doesn't seem to be any guidance in how to apply that knowledge. Or I'm just not getting it. What may…
Abel
  • 52,738
  • 19
  • 137
  • 227
6
votes
3 answers

How can I re-try a property-based-test if the randomly-generated inputs are not useful?

I am a n00b to unit testing. I have installed FsCheck.Nunit and NUnitTestAdapter from Nuget, and I'm trying to do property-based-testing, largely inspired by the inestimable Scott Wlaschin. I am using the [] attribute, and I would like the…
Overlord Zurg
  • 2,873
  • 1
  • 17
  • 22
5
votes
1 answer

FsCheck: How to generate test data that depends on other test data?

FsCheck has some neat default Arbitrary types to generate test data. However what if one of my test dates depends on another? For instance, consider the property of string.Substring() that a resulting substring can never be longer than the input…
Good Night Nerd Pride
  • 6,287
  • 3
  • 38
  • 54
5
votes
2 answers

Expecto FsCheck getting stack overflow exception when generating string

I'm trying to learn how to use FsCheck properly, and integrating it with Expecto at the moment. I can get property tests to run if I'm using the default FsCheck config, but when I try to use my own Generator, it causes a stack overflow…
kaeedo
  • 438
  • 2
  • 13
5
votes
1 answer

Test valid state transitions with scalacheck

Suppose I have this class: case class Receipt(id: Long, state: String) { def transitionTo(newState: String) = { if (!canTransitionTo(newState)) { throw new IllegalStateExcetion(s"cant transition from $state to $newState") } …
Pablo Fernandez
  • 94,980
  • 54
  • 180
  • 225
1
2 3 4 5 6 7 8