TheSeamau5 / elm-check

Property Based Testing in Elm
70 stars 20 forks source link

Concerns about elm-check integration #19

Open mgold opened 9 years ago

mgold commented 9 years ago

Hi Hassan,

I'm testing my non-empty list library and I'm adding a function that's really hard to write properties for so I'm using unit tests. I looked at the elm-test integration and, even with the README, it looks way too complicated. What I'd really like is f : Test -> Claim so I can just stick my unit tests into my property tests and call it a day. Instead I wound up hacking the output of the two libraries together. Not ideal, but it's just testing (and not even CI). Am I missing an easy way to make this work, or is there any chance you can put f on the radar?

Here is the new commit that caused all this.

TheSeamau5 commented 9 years ago

Yeah, I've been thinking on how to add this but I couldn't figure out the best way. Currently, Check and Check.Test are really like two seperate libraries. You can't use one alongside the other in a meaningful way. The reason behind this is because with Check.Test you want to generate a given number of unit tests whereas with Check you want to find just 1 failing test (theoretically, you should be able to run this process of hunting for a failing test forever).

I haven't figured out the best way to do this. But, ideally, Claim would be super generic and you could plug-in whatever you want on top of it.

So, to answer your question, yes, it has been on the radar from day one. Basically, the elm-test support that's currently here is just there cuz it's better than nothing. You get to re-use your investigators and you still get shrinking. But, different functions, different data structures, and different number of parameters so you have to slightly re-write your tests.

By the way, if you've got an idea on how to improve things, please don't hesitate. This is totally open source and I take PRs and I'm far from being an expert on testing.

rtfeldman commented 9 years ago

For what it's worth, when I use elm-check from within elm-test I use this helper function:

runCount = 100
seed = 1337

it : String -> (a -> b) -> (a -> b) -> Investigator a -> Test
it description expected actual investigator =
  Check.Test.test description actual expected investigator runCount seed

Then you can write stuff like:

suite "List.reverse" [
    it "is a no-op when applied twice"
      (identity)
      (List.reverse >> List.reverse)
      (list string)
  ]