Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableDrivenPropertyChecks + AsyncWordSpecLike not working when used together #1964

Open
camilosampedro opened this issue Feb 2, 2021 · 2 comments

Comments

@camilosampedro
Copy link

Version of scalatest: 3.0.9

When you try to create tests like:

class DummyTest extends AsyncWordSpecLike with TableDrivenPropertyChecks {
  "DummyExample" should {
    val cases = Table(
      ("foo", "bar"),
      (0, 1)
    )
    "be ok" in forAll(cases) { (foo, bar) =>
      val result: Future[Assertion] = Future {
        assert("a" == "a")
      }
      result
    } // <- forAll returns Unit, which is not the `Future[Assertion]` that Async tests expect
  }
}

The result expected by the async in {...} is Future[Assertion], but forAll returns Unit.

Is there a way to use both of them together?

@ionsquare
Copy link

Looks like there might be some discussion about this here, but not a lot of action there either...

@camilosampedro
Copy link
Author

camilosampedro commented Nov 15, 2022

Thank you @ionsquare

For reference, in case anyone is having the same issue and wants a workaround, you can use org.scalatest.wordspec.AnyWordSpecLike with org.scalatest.prop.TableDrivenPropertyChecks and org.scalatest.concurrent.ScalaFutures mix-ins and it will let you do .futureValue.

Just to oversimplify it:

val table: TableFor1[BigDecimal] = ???
val futureOperation: BigDecimal => Future[BigDecimal] = ???

"my test" should {
  "pass" in forAll(table) { foo =>
    futureOperation(foo).futureValue shouldBe 300
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants