Comments (5)
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.
@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.
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.
@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.
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)
- add conversion to `FiniteDuration` to zio.duration HOT 6
- Child fiber interrupted while parent runs onInterrupt HOT 6
- Creating highly optimized and specialized fiber mailbox HOT 16
- Performance of `ZIO.foreachPar` not as good as fork-join
- ZPool hangs during parallel item acquisition after invalidation HOT 5
- Documentation For Getting Started with ZIO HOT 5
- Optimize ZEnvironment HOT 5
- NonEmptySet#removeNonEmpty is does not remove the requested item HOT 1
- Finding implicit Tag fails sometimes for generic type argument HOT 6
- ZIO chat on zio.dev is broken HOT 1
- Documentation of ZIO's Interruption Model
- ZLayer.make fails with ClassTooLarge HOT 32
- `.map` breaks fresh layers HOT 5
- Create Loom-friendly concurrent weak set (FiberSet) HOT 9
- Missing `TestLens#cause` Macro Implementation
- Scala 2.13 - cannot compare child class to parent class in assertTrue HOT 8
- `You must not use an intersection type` when deriving ZLayer HOT 2
- ZIO does not work correctly with dependency T when T is a scala 3 opaque type HOT 15
- zio tests, missing suite constructor from ZIO[..,..,Suite[Env, Err]] HOT 2
- Add test lenses for Try HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zio.