Introduce support for effectful testing
tgrospic opened this issue · comments
Tomislav Grospić commented
Overview
Currently, we don't have support for F[_]
effectful computation in tests so tests are using _.runSyncUnsafe()
to get the value and assert result. This is not desired, recommended, runs slower and also more more difficult to read and write.
Solution
Introduce libraries to extend Scalatest and scalacheck to support working with F[_]
values without hacks.
https://typelevel.org/cats-effect/docs/2.x/guides/testing
Two libraries that we need are:
cats-effect-testing
which enables body of tests to be effect type like IO or Task
https://github.com/typelevel/cats-effect-testing#scalatestScalaCheck Effect
which enables property testing with effectful valuesforAllF
https://github.com/typelevel/scalacheck-effect#scalacheck-effect
- Upgrade Scalatest, scalacheck and scalactic to latest versions to support cats-effect-testing which can only works with Scalatest 3.1.0
https://github.com/typelevel/cats-effect-testing/blob/v0.3.0/build.sbt#L56 - Introduce
monix-testing-scalatest
library to support minix Task in tests
https://github.com/monix/monix-testing - Introduce
cats-effect-testing
andscalacheck-effect
into the project and improve InMemoryKeyValueStoreSpec and LmdbKeyValueStoreSpec by using effectful version. This means removal of _.runSyncUnsafe() by usingforAllF
instead offorAll
together with using Prop instead of assert or should (e.g.shouldBe
is the same as?=
).- examples of property based tests can be found here (for now only on feature/v0.12 branch)
- examples of property based tests can be found here (for now only on feature/v0.12 branch)
- Add WebApi tests as property based tests like for KeyValueStore. Generate arbitrary input and output data and assert ib underlying BlockApi received right input and returned right output.