Asynchronous property checking

Skip to first unread message

Luciano Leggieri

Jan 14, 2016, 9:22:36 PM1/14/16
to scalatest-users

I have a code that is doing some property testing using ScalaCheck and ScalaTest. I'll try to make a simple scenario:

I have types A and B, methods f1 and f2 both A => Future[B] and some equality method areEquals(b1: B, b2: B): Boolean

So, with an Arbitrary[A], I do a forAll that calls f1 and f2, Await.result to get the actual values from the Futures, and then calls areEquals to see that f1 and f2 return the same B for the same A.

Now let's say I want to compile this for scala.js. I don't have access to Await.result anymore because I can't block.
It's also easy to create a method areEquals(f1: Future[B], f2: Future[B]): Future[Boolean]

Good news, I can return a Future if I use AsyncFunSuite. Bad news, I think I also need changes in ScalaCheck. Basically, I think forAll should flatMap on each iteration because now each iteration returns a Future.

Is this correct? Or do you know if there's a way to do this with the current version of ScalaTest 3 and no changes in ScalaCheck?


Bill Venners

Jan 14, 2016, 11:06:46 PM1/14/16
Hi Luciano,

It can be done by adding another implicit typeclass instance for ScalaTest 3.0's forAll. It doesn't require a change to ScalaCheck or ScalaTest, though it is involved. We actually already implemented it, but I haven't included it in any 3.0 milestone because I was unsure people would actually want to do that. For such things I prefer to wait and see if users ask. You are already the second to ask, so it looks like people may indeed want it.

Chee Seng implemented it a while back. I'll follow up with him on where the implementation went and point you to it. It would be nice if you could try it out in your project.

Bill Venners
Artima, Inc.
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at
ScalaTest itself, and documentation, is available here:
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Jeff May

Mar 6, 2016, 6:50:48 PM3/6/16
to scalatest-users
+1 to this feature.

A lot of the code I am working with right now returns futures and much of my logic is held in database queries where the best way to test is by actually going out to the database and back. Not needing to use blocking calls for these tests would definitely improve the performance of running property specs for me. Right now, I block within the forAll and then the block is implicitly converted into a Future for the async test class. I would love to be able to have the forAll return a future.

Just to add, I'm super happy with the new async testing style! The output of the tests is a little unpredictable, so I tend to pack everything into the string between the "should" and "in" keywords (I'm referring to how I avoid having the first block be "A when doing B" followed by "A when doing C" etc and then that whole block is followed by half-sentences that lose their subject, ie. "should do X"). But otherwise, it has improved the performance of our tests dramatically (~3-5x). Once the rough edges like property tests are ironed out, I think this will be a very useful (and simpler) way to write tests for async code.


Alan Johnson

Mar 24, 2016, 6:25:35 PM3/24/16
to scalatest-users
Register me as a requester of this feature! I property test my DAOs, decoupled from my datastores, but the DAOs still have async interfaces. This would be very useful.

Sep 26, 2016, 8:36:38 PM9/26/16
to scalatest-users

+ 1 for the AsyncPropSpec

I am on ScalaJS so I don't even have an option to block on future (Await)

Alex Gilleran

Jan 13, 2017, 1:29:39 AM1/13/17
to scalatest-users
Did you ever find the implementation? It'd be really nice to have :)

Leif Warner

Sep 6, 2018, 7:43:30 PM9/6/18
to scalatest-users
I'd want this, as well. There's at least 3 issues filed on the GitHub issue tracker asking for this.

Matthew de Detrich

Mar 25, 2019, 12:06:47 AM3/25/19
to scalatest-users
Is there any update on this? Would be willing to make a PR if there is some direction somewhere about what could be causing the problem.

On Friday, January 15, 2016 at 3:22:36 AM UTC+1, Luciano Leggieri wrote:

Gabriel Volpe

Nov 16, 2019, 10:12:27 PM11/16/19
to scalatest-users
+1 to this feature. It's nearly 2020, are there any plans to getting it done?
Reply all
Reply to author
0 new messages