scalacheck-effect-munit


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

org.typelevel
ArtifactId

ArtifactId

scalacheck-effect-munit_0.25
Last Version

Last Version

0.0-19a059c
Release Date

Release Date

Type

Type

jar
Description

Description

scalacheck-effect-munit
scalacheck-effect-munit
Project URL

Project URL

https://github.com/typelevel/scalacheck-effect
Project Organization

Project Organization

Typelevel
Source Code Management

Source Code Management

https://github.com/typelevel/scalacheck-effect

Download scalacheck-effect-munit_0.25

How to add to project

<!-- https://jarcasting.com/artifacts/org.typelevel/scalacheck-effect-munit_0.25/ -->
<dependency>
    <groupId>org.typelevel</groupId>
    <artifactId>scalacheck-effect-munit_0.25</artifactId>
    <version>0.0-19a059c</version>
</dependency>
// https://jarcasting.com/artifacts/org.typelevel/scalacheck-effect-munit_0.25/
implementation 'org.typelevel:scalacheck-effect-munit_0.25:0.0-19a059c'
// https://jarcasting.com/artifacts/org.typelevel/scalacheck-effect-munit_0.25/
implementation ("org.typelevel:scalacheck-effect-munit_0.25:0.0-19a059c")
'org.typelevel:scalacheck-effect-munit_0.25:jar:0.0-19a059c'
<dependency org="org.typelevel" name="scalacheck-effect-munit_0.25" rev="0.0-19a059c">
  <artifact name="scalacheck-effect-munit_0.25" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.typelevel', module='scalacheck-effect-munit_0.25', version='0.0-19a059c')
)
libraryDependencies += "org.typelevel" % "scalacheck-effect-munit_0.25" % "0.0-19a059c"
[org.typelevel/scalacheck-effect-munit_0.25 "0.0-19a059c"]

Dependencies

compile (3)

Group / Artifact Type Version
org.typelevel : scalacheck-effect_0.25 jar 0.0-19a059c
ch.epfl.lamp : dotty-library_0.25 jar 0.25.0
org.scalameta : munit-scalacheck_0.25 jar 0.7.10

test (1)

Group / Artifact Type Version
org.typelevel : cats-effect_2.13 jar 2.1.4

Project Modules

There are no modules declared in this project.

ScalaCheck Effect

Continuous Integration Gitter Chat Latest version

ScalaCheck Effect is a library that extends the functionality of ScalaCheck to support "effectful" properties. An effectful property is one that evaluates each sample in some type constructor F[_]. For example:

import org.scalacheck.effect.PropF
import org.scalacheck.Test
import cats.effect.{ExitCode, IO, IOApp}

object Example extends IOApp {
  def run(args: List[String]): IO[ExitCode] = {
    val p: PropF[IO] = 
      PropF.forAllF { (x: Int) =>
        IO(x).start.flatMap(_.join).map(res => assert(res == x))
      }

    val result: IO[Test.Result] = p.check()

    result.flatMap(r => IO(println(r))).as(ExitCode.Success)
  }
}

Running this program results in the output: Result(Passed,100,0,Map(),0).

This library provides the org.scalacheck.effect.PropF type, which is the effectul analog to org.scalacheck.Prop. In this example, we use PropF.forAllF to write a property of the shape Int => IO[Unit]. This example uses cats.effect.IO as the type constructor, but any effect F[_] with an instance of MonadError[F, Throwable] can be used, including scala.concurrent.Future.

The key idea here is using the PropF.{forAllF, forAllNoShrinkF} methods to create PropF[F] instances. The check() method on PropF converts a PropF[F] to a F[Test.Result].

sbt dependency

libraryDependencies += "org.typelevel" %% "scalacheck-effect" % scalacheckEffectVersion

MUnit Integration

This project also provides support for checking PropF values from within MUnit based test suites.

import munit.{CatsEffectSuite, ScalaCheckEffectSuite}
import org.scalacheck.effect.PropF

// Example assumes https://github.com/scalameta/munit/pull/134 is merged, which adds CatsEffectSuite to munit

class ExampleSuite extends ScalaCheckEffectSuite with CatsEffectSuite {
  test("first PropF test") {
    PropF.forAllF { (x: Int) =>
      IO(x).start.flatMap(_.join).map(res => assert(res == x))
    }
  }
}

Design Goals

  • Support effectful properties without blocking.
  • Compatibility with Gen/Cogen/Arbitrary.
  • Parity with Prop features, including shrinking.
  • Follow same style as ScalaCheck and use ScalaCheck reporting.
  • Integrate well with popular test frameworks.
  • Non-goal: provide direct support for checking effectful properties directly from SBT or from standalone app.

Frequently Asked Questions

Why not just call Await.result / unsafeRunSync inside a property definition?

Calling Await.result, unsafeRunSync() or a similar blocking operation is not possible on Scala.js.

Acknowledgements

This library builds heavily on the ideas in ScalaCheck. It grew out of the FS2 AsyncPropertySuite, which only implemented a handful of features. The Weaver Test framework also has similar support for effectful properties. Finally, the Scala Hedgehog library has a prototype of similar functionality.

org.typelevel

typelevel.scala

Let the Scala compiler work for you.

Versions

Version
0.0-19a059c
0.0-7d3d904
0.0.3
0.0-aca227c