-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Layers shared between different test runs when using zio.test.check
#8585
Comments
This is not correct. This is a single test and the layer is properly constructed once for each test. There is no sharing between tests. If you want to construct the layer for each random sample you can do so by providing the layer to the workflow in import zio._
import zio.test._
object ExampleSpec extends ZIOSpecDefault {
def spec = test("foo") {
check(Gen.int(0, 10)) { testInt =>
(for {
currentValue <- ZIO.serviceWithZIO[ScopedRef[Int]](_.get) // "should" be 0 for every test
_ <- ZIO.serviceWithZIO[ScopedRef[Int]](_.set(ZIO.succeed(testInt + currentValue)))
newValue <- ZIO.serviceWithZIO[ScopedRef[Int]](_.get)
} yield assertTrue(newValue == testInt)).provideSome[Scope](ZLayer(ScopedRef.make(0)))
}
}
} |
@jdsalchow To expand a bit more, you shouldn't consider the generator something that produces/runs many different test cases. Everything happens within one test case - Since you were providing your dependency at the level of the test case, it was only "shared" across the different situations produced by the generator. |
Is there an obvious reason that checks should not "run in isolation"? My whole point here is that it's not the behaviour I would have expected :) |
@jdsalchow Really? I mean you provide on the brace that surrounds all the checks. Seems quite okay to me. And if providing to all the checks one layer should be possible, where else should you put it? 🤔 |
The semantics of I understand your desired behavior is to provide a separate copy of the layer for each sample, which is easily accomplished by providing the layer inside of Hope this helps! |
When using
zio.test.check
my expectation was that provided layers would not be shared between test runs. In my actual case I use it for e2e testing with a database that I want to be be in a pre-defined state for the test. A silly reproduction is here:I got:
The text was updated successfully, but these errors were encountered: