This part covers the ZIO tests. It is based on the documents of, Testing Effects, Testing Use Case and ZIO test effects. ZIO makes tests first-class objects in that tests are values that can be passed, transformed and composed. ZIO tests are effects.
The ZIO data type has an
R type parameter that is used to describe the type of environment required by the effect. For pure values, use
ZIO.access[R] to retrieve it. For effect value, use
ZIO.accessM[R].An effect accessed from the environment is called an environment effect. The idea behind environment effects is to program to an interface, not an implementation. You can use a test implementation for testing.
In ZIO test, all tests are immutable values that can be pure values or effects that can be defined using
testM. ZIO also provides test evnironmental effects for
Assertion class defines many assertion combinators.
Additionally, ZIO test supports test aspects
@@ for timeout or different platform. It supports property based testing and automatic derivation of generators using Magnolia module.
suite to creat a suite of tests. A suite can contain many
A test expects two arugments: a string label and an asertion of type
ZIO[R, E, TestResult]. Use
assertM method to create an assertion. Both of them accept a value of type
A or a value of
Assertion object methods to create
Assertion[A]. Prefdeind methods incude
throw and more. The result can be composed using
negate. For nested structure, methods can be cmposed using nested calls as
hasField method takes a field name, a mapping method, and an assertion.
To run a suite, override the
spec field of
DefaultRunnableSpec. For example:
DefaultRunnableSpec provides an enviornment
TestEnvironment to customize the system infrastructure.
To run the test, use
zio.test.sbt.TestFramework or invoide the