You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@avieth has notified me that I could make it even better by doing Gen (m (Test ()) instead of PropertyT IO (m (PropertyT IO ()) to get a more clear separation and intent on what's going on.
This suggests the following instance:
instanceExample (Gen (SqlPersistTIO (Test())) wheretypeArg (Gen (SqlPersistTIO (Test()))) =SqlBackend
evaluateExample example =
evaluateExample $\conn ->do
sqlAction <- forAll example
testAction <- runReaderT sqlAction conn -- using runReaderT here because the transaction is rolled back in around
test testAction -- delegate to `PropertyT IO ()` instance
And it also kinda makes sense to have an instance for functions, that uses a generator.
instanceExample (a->SqlPersistTIO (Test()) wheretypeArg (a->SqlPersistTIO (Test())) = (SqlBackend, Gena)
evaluateExample mkSqlMkTest =
evaluateExample $\(sqlBackend, gen) ->do
a <- forAll gen
testAction <- runReaderT (mkSqlMkTest a) sqlBackend
test testAction
Which lets you share generators among effectful test cases.
But, you probably don't want all of the test cases to look like that, so it's probably better for there to also be an instance:
instanceExample (a->Gen (Sql (Test()))) wheretypeArg (a->Gen (Sql (Test())) = (SqlBackend, Gena)
evaluateExample genSqlTest =
evaluateExample $\(sqlBackend, gen) ->do
a <- forAll gen
sqlTest <- forAll $ genSqlTest a
testAction <- runReaderT sqlTest sqlBackend
test testAction
which would let you generate more stuff in the thing itself.
The text was updated successfully, but these errors were encountered:
I wrote Effectful Property Tests, which solved the issue nicely for me.
@avieth has notified me that I could make it even better by doing
Gen (m (Test ())
instead ofPropertyT IO (m (PropertyT IO ())
to get a more clear separation and intent on what's going on.This suggests the following instance:
And it also kinda makes sense to have an instance for functions, that uses a generator.
Which lets you share generators among effectful test cases.
But, you probably don't want all of the test cases to look like that, so it's probably better for there to also be an instance:
which would let you generate more stuff in the thing itself.
The text was updated successfully, but these errors were encountered: