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 specificationZSpec
- An alias for aSpec
whose tests are ZIO effectsPredicate
- Composable predicates with detailed error messageszio.test.{ assert, assertM, check, checkAll, checkSome, suite, test, testM }
- The building blocks for constructing specsRunnableSpec
- Specs will extend this (orDefaultRunnableSpec
)TestRunner
- Every runnable spec points to a spec runnerTestAspect
- 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:
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 ZIO#foldCause (#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 ZIO#eventually (#1302) by @vasilmkd
- Add ZIO#left, ZIO#right and ZIO#head (#1223) by @adamgfraser
- Add ZIO#flattenErrorOption, ZIO#none, ZIO#optional, ZIO#some (#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 ZStream#ensuringFirst (#1209) by @adamgfraser
- Make ZManaged#mergeAllParN and ZManaged#reduceAllParN 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 ZStream#throttleEnforce and ZStream#throttleEnforceM (#1027) (#1155) by @vasilmkd
- Add ZStream#throttleShape, ZStream#throttleShapeM (#1195) by @vasilmkd
- Add ZStream#effectAsync and variants (#1118) by @dariusrobson
- Add ZStream#aggregate, ZStream#aggregateWithin (#1137) by @iravid
- Add burst control to the existing Stream throttling combinators (#1205) by @vasilmkd
- Add ZStream#flatMapParSwitch (#1222) by @vasilmkd
- Add sinks for decoding UTF-8 bytes and byte chunks (#1342) by @iravid