package test
_ZIO Test_ is a featherweight testing library for effectful programs.
The library imagines every spec as an ordinary immutable value, providing tremendous potential for composition. Thanks to tight integration with ZIO, specs can use resources (including those requiring disposal), have well- defined linear and parallel semantics, and can benefit from a host of ZIO combinators.
import zio.test._ import zio.clock.nanoTime import Assertion.isGreaterThan object MyTest extends DefaultRunnableSpec { suite("clock") { testM("time is non-zero") { assertM(nanoTime, isGreaterThan(0)) } } }
- Alphabetic
- By Inheritance
- test
- CompileVariants
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Package Members
- package environment
The
environment
package contains testable versions of all the standard ZIO environment types through the TestClock, TestConsole, TestSystem, and TestRandom modules.The
environment
package contains testable versions of all the standard ZIO environment types through the TestClock, TestConsole, TestSystem, and TestRandom modules. See the documentation on the individual modules for more detail about using each of them.If you are using ZIO Test and extending
DefaultRunnableSpec
aTestEnvironment
containing all of them will be automatically provided to each of your tests. Otherwise, the easiest way to use the test implementations in ZIO Test is by providing theTestEnvironment
to your program.import zio.test.environment._ myProgram.provideManaged(testEnvironmentManaged)
Then all environmental effects, such as printing to the console or generating random numbers, will be implemented by the
TestEnvironment
and will be fully testable. When you do need to access the "live" environment, for example to print debugging information to the console, just use thelive
combinator along with the effect as your normally would.If you are only interested in one of the test implementations for your application, you can also access them a la carte through the
make
method on each module. Each test module requires some data on initialization. Default data is included for each asDefaultData
.import zio.test.environment._ myProgram.provideM(TestConsole.make(TestConsole.DefaultData))
Finally, you can create a
Test
object that implements the test interface directly using themakeTest
method. This can be useful when you want to access some testing functionality without using the environment type.import zio.test.environment._ for { testRandom <- TestRandom.makeTest(TestRandom.DefaultData) n <- testRandom.nextInt } yield n
This can also be useful when you are creating a more complex environment to provide the implementation for test services that you mix in.
- package mock
- package reflect
Type Members
- abstract class AbstractRunnableSpec extends AnyRef
- Annotations
- @EnableReflectiveInstantiation()
- type AssertResult = BoolAlgebra[AssertionValue]
- class Assertion[-A] extends (=> A) => AssertResult
An
Assertion[A]
is capable of producing assertion results on anA
.An
Assertion[A]
is capable of producing assertion results on anA
. As a proposition, assertions compose using logical conjuction and disjunction, and can be negated. - sealed trait AssertionValue extends AnyRef
An
AssertionValue
keeps track of a assertion and a value, existentially hiding the type.An
AssertionValue
keeps track of a assertion and a value, existentially hiding the type. This is used internally by the library to provide useful error messages in the event of test failures. - sealed trait BoolAlgebra[+A] extends Product with Serializable
A
BoolAlgebra[A]
is a description of logical operations on values of typeA
. - trait CompileVariants extends AnyRef
- abstract class DefaultRunnableSpec extends RunnableSpec[TestEnvironment, String, Any, Any, Any]
A default runnable spec that provides testable versions of all of the modules in ZIO (Clock, Random, etc).
- type ExecutedSpec[+L, +E, +S] = Spec[Any, Nothing, L, Either[TestFailure[E], TestSuccess[S]]]
An
ExecutedSpec
is a spec that has been run to produce test results. - sealed trait ExecutionStrategy extends AnyRef
- final case class FailureDetails(assertion: ::[AssertionValue], gen: Option[GenFailureDetails] = None) extends Product with Serializable
FailureDetails
keeps track of details relevant to failures. - trait FunctionVariants extends AnyRef
- case class Gen[-R, +A](sample: ZStream[R, Nothing, Sample[R, A]]) extends Product with Serializable
A
Gen[R, A]
represents a generator of values of typeA
, which requires an environmentR
.A
Gen[R, A]
represents a generator of values of typeA
, which requires an environmentR
. Generators may be random or deterministic. - sealed trait GenFailureDetails extends AnyRef
GenFailureDetails
keeps track of relevant information related to a failure in a generative test. - trait GenZIO extends AnyRef
- case class RenderedResult(caseType: CaseType, label: String, status: Status, offset: Int, rendered: Seq[String]) extends Product with Serializable
- abstract class RunnableSpec[R, L, T, E, S] extends AbstractRunnableSpec
A
RunnableSpec
has a main function and can be run by the JVM / Scala.js. - final case class Sample[-R, +A](value: A, shrink: ZStream[R, Nothing, Sample[R, A]]) extends Product with Serializable
A sample is a single observation from a random variable, together with a tree of "shrinkings" used for minimization of "large" failures.
- trait Sized extends AnyRef
- final case class Spec[-R, +E, +L, +T](caseValue: SpecCase[R, E, L, T, Spec[R, E, L, T]]) extends Product with Serializable
A
Spec[R, E, L, T]
is the backbone of _ZIO Test_.A
Spec[R, E, L, T]
is the backbone of _ZIO Test_. Every spec is either a suite, which contains other specs, or a test of typeT
. All specs are annotated with labels of typeL
, require an environment of typeR
and may potentially fail with an error of typeE
. - final class TestAnnotation[V] extends AnyRef
A type of annotation.
- class TestAnnotationMap extends AnyRef
An annotation map keeps track of annotations of different types.
- case class TestArgs(testSearchTerms: List[String]) extends Product with Serializable
- trait TestAspect[+LowerR, -UpperR, +LowerE, -UpperE, +LowerS, -UpperS] extends AnyRef
A
TestAspect
is an aspect that can be weaved into specs.A
TestAspect
is an aspect that can be weaved into specs. You can think of an aspect as a polymorphic function, capable of transforming one test into another, possibly enlarging the environment, error, or success type. - type TestAspectPoly = TestAspect[Nothing, Any, Nothing, Any, Nothing, Any]
A
TestAspectPoly
is aTestAspect
that is completely polymorphic, having no requirements on error or environment. - type TestExecutor[+R, L, -T, E, +S] = (ZSpec[R, E, L, T], ExecutionStrategy) => UIO[ExecutedSpec[L, E, S]]
A
TestExecutor[R, L, T, E, S]
is capable of executing specs containing tests of typeT
, annotated with labels of typeL
, that require an environmentR
and may fail with anE
or succeed with aS
. - sealed trait TestFailure[+E] extends AnyRef
- trait TestLogger extends AnyRef
- type TestReporter[-L, -E, -S] = (Duration, ExecutedSpec[L, E, S]) => URIO[TestLogger, Unit]
A
TestReporter[L, E, S]
is capable of reporting test results annotated with labelsL
, error typeE
, and success typeS
. - type TestResult = BoolAlgebra[FailureDetails]
- case class TestRunner[R, L, -T, E, S](executor: TestExecutor[R, L, T, E, S], platform: Platform = PlatformLive.makeDefault().withReportFailure(_ => ()), reporter: TestReporter[L, E, S] = DefaultTestReporter()) extends Product with Serializable
A
TestRunner[R, E, L, S]
encapsulates all the logic necessary to run specs that require an environmentR
and may fail with an errorE
or succeed with anS
, using labels of typeL
.A
TestRunner[R, E, L, S]
encapsulates all the logic necessary to run specs that require an environmentR
and may fail with an errorE
or succeed with anS
, using labels of typeL
. Test runners require a test executor, a platform, and a reporter. - sealed trait TestSuccess[+S] extends AnyRef
- final case class TestTimeoutException(message: String) extends Throwable with Product with Serializable
- trait TimeVariants extends AnyRef
- trait TimeoutVariants extends AnyRef
- type ZSpec[-R, +E, +L, +S] = Spec[R, TestFailure[E], L, TestSuccess[S]]
A
ZSpec[R, E, L, S]
is the canonical spec for testing ZIO programs.A
ZSpec[R, E, L, S]
is the canonical spec for testing ZIO programs. The spec's test type is a ZIO effect that requires anR
, might fail with anE
, might succeed with anS
, and whose nodes are annotated with labelsL
. - type ZTest[-R, +E, +S] = ZIO[R, TestFailure[E], TestSuccess[S]]
A
ZTest[R, E, S]
is an effectfully produced test that requires anR
and may fail with anE
or succeed with aS
.
Value Members
- final def assert[A](value: => A, assertion: Assertion[A]): TestResult
Checks the assertion holds for the given value.
- final val assertCompletes: TestResult
Asserts that the given test was completed.
- final def assertM[R, E, A](value: ZIO[R, E, A], assertion: Assertion[A]): ZIO[R, E, TestResult]
Checks the assertion holds for the given effectfully-computed value.
- final def check[R, A, B, C, D](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])(test: (A, B, C, D) => TestResult): ZIO[R, Nothing, TestResult]
A version of
check
that accepts four random variables. - final def check[R, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(test: (A, B, C) => TestResult): ZIO[R, Nothing, TestResult]
A version of
check
that accepts three random variables. - final def check[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) => TestResult): ZIO[R, Nothing, TestResult]
A version of
check
that accepts two random variables. - final def check[R, A](rv: Gen[R, A])(test: (A) => TestResult): ZIO[R, Nothing, TestResult]
Checks the test passes for "sufficient" numbers of samples from the given random variable.
- final def checkAll[R, A, B, C, D](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])(test: (A, B, C, D) => TestResult): ZIO[R, Nothing, TestResult]
A version of
checkAll
that accepts four random variables. - final def checkAll[R, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(test: (A, B, C) => TestResult): ZIO[R, Nothing, TestResult]
A version of
checkAll
that accepts three random variables. - final def checkAll[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) => TestResult): ZIO[R, Nothing, TestResult]
A version of
checkAll
that accepts two random variables. - final def checkAll[R, A](rv: Gen[R, A])(test: (A) => TestResult): ZIO[R, Nothing, TestResult]
Checks the test passes for all values from the given random variable.
Checks the test passes for all values from the given random variable. This is useful for deterministic
Gen
that comprehensively explore all possibilities in a given domain. - final def checkAllM[R, R1 <: R, E, A, B, C, D](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])(test: (A, B, C, D) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
A version of
checkAllM
that accepts four random variables. - final def checkAllM[R, R1 <: R, E, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(test: (A, B, C) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
A version of
checkAllM
that accepts three random variables. - final def checkAllM[R, R1 <: R, E, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
A version of
checkAllM
that accepts two random variables. - final def checkAllM[R, R1 <: R, E, A](rv: Gen[R, A])(test: (A) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
Checks the effectual test passes for all values from the given random variable.
Checks the effectual test passes for all values from the given random variable. This is useful for deterministic
Gen
that comprehensively explore all possibilities in a given domain. - final def checkM[R, R1 <: R, E, A, B, C, D](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])(test: (A, B, C, D) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
A version of
checkM
that accepts four random variables. - final def checkM[R, R1 <: R, E, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(test: (A, B, C) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
A version of
checkM
that accepts three random variables. - final def checkM[R, R1 <: R, E, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
A version of
checkM
that accepts two random variables. - final def checkM[R, R1 <: R, E, A](rv: Gen[R, A])(test: (A) => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
Checks the effectual test passes for "sufficient" numbers of samples from the given random variable.
- final def checkSome(n: Int): CheckSome
Checks the test passes for the specified number of samples from the given random variable.
- final def checkSomeM(n: Int): CheckSomeM
Checks the effectual test passes for the specified number of samples from the given random variable.
- final def failed[E](cause: Cause[E]): ZTest[Any, E, Nothing]
Creates a failed test result with the specified runtime cause.
- final val ignored: ZTest[Any, Nothing, Nothing]
Creates an ignored test result.
- final def platformSpecific[R, E, A, S](js: => A, jvm: => A)(f: (A) => ZTest[R, E, S]): ZTest[R, E, S]
Passes platform specific information to the specified function, which will use that information to create a test.
Passes platform specific information to the specified function, which will use that information to create a test. If the platform is neither ScalaJS nor the JVM, an ignored test result will be returned.
- final def suite[R, E, L, T](label: L)(specs: Spec[R, E, L, T]*): Spec[R, E, L, T]
Builds a suite containing a number of other specs.
- final def test[L](label: L)(assertion: => TestResult): ZSpec[Any, Nothing, L, Unit]
Builds a spec with a single pure test.
- final def testM[R, E, L](label: L)(assertion: => ZIO[R, E, TestResult]): ZSpec[R, E, L, Unit]
Builds a spec with a single effectful test.
- final macro def typeCheck(code: String): UIO[Either[String, Unit]]
Returns either
Right
if the specified string type checks as valid Scala code orLeft
with an error message otherwise.Returns either
Right
if the specified string type checks as valid Scala code orLeft
with an error message otherwise. Dies with a runtime exception if specified string cannot be parsed or is not a known value at compile time.- Definition Classes
- CompileVariants
- final def versionSpecific[R, E, A, S](dotty: => A, scala2: => A)(f: (A) => ZTest[R, E, S]): ZTest[R, E, S]
Passes version specific information to the specified function, which will use that information to create a test.
Passes version specific information to the specified function, which will use that information to create a test. If the version is neither Dotty nor Scala 2, an ignored test result will be returned.
- object Assertion
- object AssertionValue
- object BoolAlgebra extends Serializable
- object CheckVariants
- object DefaultTestReporter
- object DefaultTestRunner extends TestRunner[TestEnvironment, String, Any, Any, Any]
A
Runner
that provides a default testable environment. - object ExecutionStrategy
- object Gen extends GenZIO with FunctionVariants with TimeVariants with Serializable
- object GenFailureDetails
- object RenderedResult extends Serializable
- object Sample extends Serializable
- object Sized
- object Spec extends Serializable
- object SummaryBuilder
- object TestAnnotation
- object TestAnnotationMap
- object TestArgs extends Serializable
- object TestAspect extends TimeoutVariants
- object TestExecutor
- object TestFailure
- object TestLogger
- object TestPlatform
TestPlatform
provides information about the platform tests are being run on to enable platform specific test configuration. - object TestReporter
- object TestSuccess
- object TestVersion
TestVersion
provides information about the Scala version tests are being run on to enable platform specific test configuration.