ZIO Test
Early beta version of dependency-free test library for (pure FP) effectful programs. Critical constructs include:
- `Spec` - A value-level representation for a specification
- `ZSpec` - An alias for a `Spec` whose tests are ZIO effects
- `Predicate` - Composable predicates with detailed error messages
- `zio.test.{ assert, assertM, check, checkAll, checkSome, suite, test, testM }` - The building blocks for constructing specs
- `RunnableSpec` - Specs will extend this (or `DefaultRunnableSpec`)
- `TestRunner` - Every runnable spec points to a spec runner
- `TestAspect` - Features that can be added to specs, such as timeouts, retries, etc.
- `Gen` - Generators for property-testing based on ZIO Stream
ZIO Test has excellent support for environmental effects; specs that use the ZIO environmental effects (Console, Clock, etc.) will automatically (in `DefaultRunnableSpec`) be provided with a newly-created mock environment, meaning they will execute fast and deterministically. Users can supply their own mock environments when extending `RunnableSpec`.
ZIO Test Example:
scala
class MySpec extends DefaultRunnableSpec {
import Predicate._
import zio.random._
import zio.test.TestAspect.{ flaky, timeout }
suite("An example suite") {
test("addition") {
assert(2 + 2, equals(4))
},
testM("random.nextDouble") {
assertM(nextDouble, isGreaterThanEqual(0.0) && isLessThanEqual(1.0))
},
(flaky >>> timeout(10.seconds)) {
testM("flaky random.nextDouble") {
assertM(nextDouble, isGreaterThan(0.5))
}
}
}
}
Other notable changes
ZIO
* Enhance support for Option and Either (1175) by dorsev
* Add Random.shuffle method (1185) by ioleo
* Add real companion objects to Task, TaskR, UIO and IO (805) by TheMayoras
* Rename TaskR to RIO and add an alias `UIOR[R, A] = ZIO[R, Nothing, A]` (1154) by ioleo
* Fix 1165 - ZIO.foreachParN should not use more than `n` fibers (1187) by adamgfraser
* Implement ZIOfoldCause (1243) by vasilmkd
* Add whenCase and whenCaseM to ZIO and ZManaged (1246) by ghostdogpr
* Add "Setter" / "Update" Methods to Mock Services (1252) by adamgfraser
* Add ZIO.replicate method (1262) by dorsev
* Add ZIOeventually (1302) by vasilmkd
* Add ZIOleft, ZIOright and ZIOhead (1223) by adamgfraser
* Add ZIOflattenErrorOption, ZIOnone, ZIOoptional, ZIOsome (1221) by jczuchnowski
* Add ZIO.effectSuspend, ZIO.effectSuspendTotal, ZIO.effectSuspendTotalWith and ZIO.effectSuspendWith (926) by kamilkloch
ZManaged
* Introduce real companion object for Managed (1111) (1169) by andreamarcolin
* Add ZStreamensuringFirst (1209) by adamgfraser
* Make ZManagedmergeAllParN and ZManagedreduceAllParN tolerant to finalizer defects (1256) by adamgfraser
* Add ZManaged.makeExit that allows to handle `Exit` by the finalizer. (1232) by vvlevykin
ZSchedule
* add doWhileM, doUntilM for ZSchedule (1199) by contrun
* add collectWhile and collectUntil (1287) by contrun
ZStream and ZSink
* Enhanced ZStream spaced to also emit schedule's output (1120) (1162) by dag2ww
* Add ZStreamthrottleEnforce and ZStreamthrottleEnforceM (1027) (1155) by vasilmkd
* Add ZStreamthrottleShape, ZStreamthrottleShapeM (1195) by vasilmkd
* Add ZStreameffectAsync and variants (1118) by dariusrobson
* Add ZStreamaggregate, ZStreamaggregateWithin (1137) by iravid
* Add burst control to the existing Stream throttling combinators (1205) by vasilmkd
* Add ZStreamflatMapParSwitch (1222) by vasilmkd
* Add sinks for decoding UTF-8 bytes and byte chunks (1342) by iravid
Promise
* Changed Promisedone to take an Exit (1251) by mtsokol
Semaphore
* Implement SemaphorewithPermitsManaged (1293) by vasilmkd