property-based-testing

Generating list of lists with custom value limitations with Hypothesis

て烟熏妆下的殇ゞ 提交于 2019-12-10 01:42:55
问题 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 (rectangular form) and should be >= 0 and <= 5 values inside sublists cannot be more than or equal to the total number of sublists. In other words, each value inside a sublist is an integer >= 0 and < N Sample valid inputs: [[0]] [[2, 1], [2, 0], [3, 1], [1,

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

自闭症网瘾萝莉.ら 提交于 2019-12-06 02:47:55
问题 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 make it harder to grasp is that the relation between tests, properties, generators, arbitraries, shrinking and, in my case, randomness (some tests automatically generate random data, others don't) is not clear to me. I don't have a Haskell

Pattern for generating negative Scalacheck scenarios: Using property based testing to test validation logic in Scala

*爱你&永不变心* 提交于 2019-12-05 14:09:07
We are looking for a viable design pattern for building Scalacheck Gen (generators) that can produce both positive and negative test scenarios. This will allow us to run forAll tests to validate functionality (positive cases), and also verify that our case class validation works correctly by failing on all invalid combinations of data. Making a simple, parameterized Gen that does this on a one-off basis is pretty easy. For example: def idGen(valid: Boolean = true): Gen[String] = Gen.oneOf(ID.values.toList).map(s => if (valid) s else Gen.oneOf(simpleRandomCode(4), "").sample.get) With the above

Generating list of lists with custom value limitations with Hypothesis

点点圈 提交于 2019-12-05 00:45:40
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 (rectangular form) and should be >= 0 and <= 5 values inside sublists cannot be more than or equal to the total number of sublists. In other words, each value inside a sublist is an integer >= 0 and < N Sample valid inputs: [[0]] [[2, 1], [2, 0], [3, 1], [1, 0]] [[1], [0]] Sample invalid inputs: [[2]] # 2 is more than N=1 (total number of sublists) [[0, 1], [2

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

被刻印的时光 ゝ 提交于 2019-12-04 09:36:01
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 make it harder to grasp is that the relation between tests, properties, generators, arbitraries, shrinking and, in my case, randomness (some tests automatically generate random data, others don't) is not clear to me. I don't have a Haskell background so that doesn't help much either. Now for the question: how do I generate random integers? My test

how to use xUnit and FsCheck with IoC and mocking in F#

∥☆過路亽.° 提交于 2019-12-04 06:40:46
问题 I want to write unit tests F# using property base testing technic. however I came across several obstacle. Code I want to test is in C# Domain objects come from EF i.e. no constructors only mutable properties sut is a class that will require a lot of constructor injections. Their number will change quite frequently as we add new functions. We do not want to change old tests when we add new parameter to constructor. sut already exists and is working so changing it pattern to take only one