---
layout: default
title: Using QuickCheck with Hspec
---

You can use arbitrary QuickCheck properties with Hspec, but they must be of
type {{'Property'|id}}.  QuickCheck's {{'property'|id}} function can be used to
turn anything that is a member of the {{'Testable'|id}} class into a
{{'Property'|id}}.  Here is an example:

```hspec
describe "read" $ do
  it "is inverse to show" $ property $
    \x -> (read . show) x == (x :: Int)
```

{% example QuickCheck.hs %}

It's also possible to modify some of the arguments passed to the Quickcheck
driver, namely: the maximum number of successes before succeeding, the maximum
number of discarded tests per successful test before giving up and the size of
the test case:

```hspec
import Test.Hspec.Core.QuickCheck (modifyMaxSuccess)

describe "read" $ do
  modifyMaxSuccess (const 1000) $ it "is inverse to show" $ property $
    \x -> (read . show) x == (x :: Int)
```

---
layout: default
title: Using QuickCheck with Hspec
---

You can use arbitrary QuickCheck properties with Hspec, but they must be of
type {{'Property'|id}}.  QuickCheck's {{'property'|id}} function can be used to
turn anything that is a member of the {{'Testable'|id}} class into a
{{'Property'|id}}.  Here is an example:

```hspec
describe "read" $ do
  it "is inverse to show" $ property $
    \x -> (read . show) x `shouldBe` (x :: Int)
```

{% example QuickCheck.hs %}

It's also possible to modify some of the arguments passed to the Quickcheck
driver, namely: the maximum number of successes before succeeding, the maximum
number of discarded tests per successful test before giving up and the size of
the test case:

```hspec
import Test.Hspec.Core.QuickCheck (modifyMaxSuccess)

describe "read" $ do
  modifyMaxSuccess (const 1000) $ it "is inverse to show" $ property $
    \x -> (read . show) x `shouldBe` (x :: Int)
```

Use `shouldBe` instead of == in property test docs.
Use `shouldBe` instead of == in property test docs.

If a test fails, this will show "expected ... but got ..." instead of just the value generated by QuickCheck, which is 1000x more useful.
