Created
December 20, 2018 14:22
-
-
Save Daenyth/249952f96dd3ca2aff55a2dae17d19af to your computer and use it in GitHub Desktop.
Save scalacheck generated data as json on failure in scalatest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestFailExample extends FlatSpec with GeneratorDriverPropertyChecks | |
it should "foo" in { | |
val genData: Gen[T] | |
IO( | |
forAll(genData) { | |
// test here | |
} | |
).onError { | |
case e: GeneratorDrivenPropertyCheckFailedException => | |
val data = e.args.head | |
.asInstanceOf[Prop.Arg[T]] | |
.arg | |
val path = new File("test_fail_data.json").toPath | |
fs2.Stream | |
.emit(data.toJson.compactPrint) // spray, but could be anything | |
.covary[IO] | |
.through(fs2.text.utf8Encode) | |
.to( | |
fs2.io.file.writeAll[IO](path) | |
) | |
.compile | |
.drain | |
} | |
.unsafeRunSync() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment