Skip to content

Batch assertion mode support #6195

@TomerAberbach

Description

@TomerAberbach

🚀 Feature Request

Motivation

I'm working on a library and am trying to apply property-based testing to it. I have an assertion that is expensive to run even on a single generated value. As a result, the property-based testing is way too slow.

I was thinking about how to solve this and realized my assertion has a constant factor that makes it slow. If I could receive multiple values at the same time and assert on them together, then this would barely be slower than asserting on a single value (up to a point), and after the assertion I can deduce which values failed the assertion.

So this gave me the following idea: What if fast-check allowed you to specify "please provide me values in batches of size 50" and then the end-user is responsible for asserting on all values together and return to fast-check the values that failed.

Example

This is a sketch and doesn't have to be the final public API:

test.prop([fc.double()], { batch: 50 })(`something`, (values) => {
  const badValues = someExpensiveMethod(values)

  reportFailingValues(badValues)
  expect(badValues).toStrictEqual([])
})

NOTE: For now I'm doing fc.array(myArbitrary, { minLength: 1 }) and limiting numRuns to a smaller number to get a similar behavior. It's unclear to me if the behavior I'm getting from this is actually equivalent to what I'm suggesting above. I suspect with the above feature fast-check could maybe be smarter, but I'm not sure.

Curious what you think!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions