Giter VIP home page Giter VIP logo

Comments (5)

adamgfraser avatar adamgfraser commented on June 21, 2024

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 check.

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)))
    }
  }
}

from zio.

swoogles avatar swoogles commented on June 21, 2024

@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 - "foo".

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.

from zio.

jdsalchow avatar jdsalchow commented on June 21, 2024

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 :)

from zio.

987Nabil avatar 987Nabil commented on June 21, 2024

@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? 🤔
And it is also consistent with how you would run an app. You provide once on the outside, and every effect that requires the layer gets the same layer.

from zio.

adamgfraser avatar adamgfraser commented on June 21, 2024

The semantics of provide is that it provides a separate copy of the layer to each test. A sample in a property based test is not a test. The test is the thing labeled foo that gets reported in your test output. If a property based fails after 42 iterations the result is that there is 1 test failure, not 42 test failures and 1 test success.

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 check and follows normal scoping rules. However, other users do not desire this . For example, their samples do not interfere with each other or they do necessary cleanup and they do not want to make their property based tests slower by building the layer for each sample. Your change would make that impossible.

Hope this helps!

from zio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.