Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xUnit integration #144

Closed
cmeeren opened this issue Oct 27, 2017 · 5 comments
Closed

xUnit integration #144

cmeeren opened this issue Oct 27, 2017 · 5 comments
Labels

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Oct 27, 2017

When auto-generation (#133) is implemented (e.g. in Hedgehog.Experimental as discussed in #139), it might be nice to offer a simple kind of xUnit integration (similar to FsCheck) that can be used for simple purposes (for example in a new assembly Hedgehog.Xunit that depends on Hedgehog.Experimental). It might turn out to be counterproductive, but I'm opening an issue anyway so it can be discussed. Here's what I'm talking about:

A simple test using the current API, where all values can be auto-generated:

[<Fact>]
let ``Reverse of reverse of a list is the original list`` () =
  Property.check <| property {
    let! (xs : int list) = Gen.auto()
    return xs |> List.rev |> List.rev = xs
  }

The same simple test in a proposed new API (note the new attribute):

[<Property>]
let ``Reverse of reverse of a list is the original list`` (xs : int list) =
    xs |> List.rev |> List.rev = xs

One could customize the run using the attribute, e.g. [<Property(Tests=500)>].

Open questions:

  1. Will this push developers away from best practices? I can imagine the simpler syntax being used in cases where the full property { } syntax would be a better choice.

  2. Are there actually that many usecases where one can rely exclusively on auto-generated values? I have currently only used Hedgehog in a single (real-life) project, but in that specific example, that's definitely not the case - I require more control.

  3. The need for more control over the generation could be alleviated somewhat (not fully) by filtering. But how should this be done? Without a property expression, the where clause isn't available. (FsCheck has its own operator for this, <boolExpression> ==> [lazy] <restOfTest>.)

  4. What happens when not all values can be auto-generated? One could force the user to use the normal API, or we could have a slightly simplified combined API like this:

[<Property>]
let ``Some other test`` (xs : int list) = property {
    let! otherValue = Gen.somethingNotAuto |> Gen.combinatorStuff |> Gen.etc
    ...
  }

All of the above points considered, I'm not convinced this is a good idea, but it has its use cases.

@moodmosaic
Copy link
Member

In order for this to work, you'll need the Gen.auto first in Hedgehog.Experimental.

Then, this hypothetical [<Property>] in your examples may use Gen.auto to provide values for the params. At this point, how would you override what Gen.auto does?

@cmeeren
Copy link
Contributor Author

cmeeren commented Oct 27, 2017

That could be done using the attribute:

[<Property(Gens={Gen.defaults with Char = Gen.alphaNum})>]

@moodmosaic
Copy link
Member

Are you sure this will actually compile?

@cmeeren
Copy link
Contributor Author

cmeeren commented Oct 27, 2017

Well that's a good question, I didn't think of that. No, I don't think that will compile.

@moodmosaic
Copy link
Member

Closing this as I can't see an easy way of overriding the defaults in the hypothetical Gen.auto generator. Feel free to add comments to this issue, if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants