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 Predicate.gt object MyTest extends DefaultRunnableSpec { suite("clock") { testM("time is non-zero") { assertM(nanoTime, gt(0)) } } }
- Alphabetic
- By Inheritance
- test
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- sealed trait Assertion[+A] extends AnyRef
An
Assertion[A]
is the result of running a test, which may be ignore, success, or failure, with some message of typeA
. - abstract class DefaultRunnableSpec extends RunnableSpec[String, ZTest[MockEnvironment, Any]]
A default runnable spec that provides testable versions of all of the modules in ZIO (Clock, Random, etc).
- type ExecutedSpec[+L] = Spec[L, TestResult]
An
ExecutedSpec
is a spec that has been run to produce test results. - sealed trait ExecutionStrategy extends AnyRef
- sealed trait FailureDetails extends AnyRef
FailureDetails
keeps track of details relevant to failures. - 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. - class Predicate[-A] extends (=> A) => PredicateResult
A
Predicate[A]
is capable of producing assertion results on anA
.A
Predicate[A]
is capable of producing assertion results on anA
. As a proposition, predicates compose using logical conjuction and disjunction, and can be negated. - type PredicateResult = Assertion[PredicateValue]
- sealed trait PredicateValue extends AnyRef
A
PredicateValue
keeps track of a predicate and a value, existentially hiding the type.A
PredicateValue
keeps track of a predicate 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. - abstract class RunnableSpec[+L, +T] extends AnyRef
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, A]) extends Product with Serializable
A sample is a single observation from a random variable, together with a stream of "shrinkings" used for minimization of "large" failures.
- final case class Spec[+L, +T](caseValue: SpecCase[L, T, Spec[L, T]]) extends Product with Serializable
A
Spec[L, T]
is the backbone of _ZIO Test_.A
Spec[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
. - trait TestAspect[+LowerR, -UpperR, +LowerE, -UpperE] 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 or error type. - type TestAspectPoly = TestAspect[Nothing, Any, Nothing, Any]
A
TestAspectPoly
is aTestAspect
that is completely polymorphic, having no requirements on error or environment. - type TestExecutor[L, -T] = (Spec[L, T], ExecutionStrategy) => UIO[ExecutedSpec[L]]
A
TestExecutor[L, T]
is capable of executing specs containing tests of typeT
, annotated with labels of typeL
. - type TestReporter[-L] = (ExecutedSpec[L]) => UIO[Unit]
A
TestReporter[L]
is capable of reporting test results annotated with labelsL
. - type TestResult = Assertion[FailureDetails]
- abstract class TestRunner[L, -T] extends AnyRef
A
TestRunner[R, E, L]
encapsulates all the logic necessary to run specs that require an environmentR
and may fail with an errorE
, using labels of typeL
.A
TestRunner[R, E, L]
encapsulates all the logic necessary to run specs that require an environmentR
and may fail with an errorE
, using labels of typeL
. Test runners require a test executor, a platform, and a reporter. - type ZSpec[-R, +E, +L] = Spec[L, ZTest[R, E]]
A
ZSpec[R, E, L]
is the canonical spec for testing ZIO programs.A
ZSpec[R, E, L]
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 aTestResult
, and whose nodes are annotated with labelsL
. - implicit class ZSpecSyntax[R, E, L] extends AnyRef
Adds syntax for adding aspects.
Adds syntax for adding aspects.
test("foo") { assert(42, equals(42)) } @@ ignore
- type ZTest[-R, +E] = ZIO[R, E, TestResult]
A
ZTest[R, E]
is an effectfully produced test that requires anR
and may fail with anE
.
Value Members
- final def assert[A](value: => A, predicate: Predicate[A]): TestResult
Asserts the given value satisfies the given predicate.
- final def assertM[R, A](value: ZIO[R, Nothing, A], predicate: Predicate[A]): ZTest[R, Nothing]
Asserts the given effectfully-computed value satisfies the given predicate.
- final def check[R, A](rv: Gen[R, A])(predicate: Predicate[A]): ZTest[R, Nothing]
Checks the predicate holds for "sufficient" numbers of samples from the given random variable.
- final def checkAll[R, A](rv: Gen[R, A])(predicate: Predicate[A]): ZTest[R, Nothing]
Checks the predicate holds for all values from the given random variable.
Checks the predicate holds 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 checkSome[R, A](n: Int)(rv: Gen[R, A])(predicate: Predicate[A]): ZTest[R, Nothing]
Checks the predicate holds for the specified number of samples from the given random variable.
- final def fail[E](cause: Cause[E]): TestResult
Creates a failed test result with the specified runtime cause.
- final def suite[L, T](label: L)(specs: Spec[L, T]*): Spec[L, T]
Builds a suite containing a number of other specs.
- final def test[L](label: L)(assertion: => TestResult): ZSpec[Any, Nothing, L]
Builds a spec with a single pure test.
- final def testM[L, T](label: L)(assertion: T): Spec[L, T]
Builds a spec with a single effectful test.
- object Assertion
- object DefaultTestReporter
- object DefaultTestRunner extends TestRunner[String, ZTest[MockEnvironment, Any]]
A
Runner
that provides a default testable environment. - object ExecutionStrategy
- object FailureDetails
- object Gen extends Serializable
- object Predicate
- object PredicateValue
- object Sample extends Serializable
- object Spec extends Serializable
- object TestAspect
- object TestExecutor