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
- CheckVariants
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Package Members
- package mock
The
mockpackage contains testable versions of all the standard ZIO environment types through the MockClock, MockConsole, MockSystem, and MockRandom modules.The
mockpackage contains testable versions of all the standard ZIO environment types through the MockClock, MockConsole, MockSystem, and MockRandom modules. See the documentation on the individual modules for more detail about using each of them.If you are using ZIO Test and extending
DefaultRunnableSpecaMockEnvironmentcontaining all of them will be automatically provided to each of your tests. Otherwise, the easiest way to use the mocking functionality in ZIO Test is by providing theMockEnvironmentto your program.import zio.test.mock._ myProgram.provideManaged(mockEnvironmentManaged)Then all environmental effects, such as printing to the console or generating random numbers, will be implemented by the
MockEnvironmentand will be fully testable. When you do need to access the "live" environment, for example to print debugging information to the close, just use thelivecombinator along with the effect as your normally would.If you are only interested in one of the mocking modules for your application, you can also access them a la carte through the
makemethod on each module. Each mock module requires some data on initialization. Default data is included for each asDefaultData.import zio.test.mock._ myProgram.provideM(MockConsole.make(MockConsole.DefaultData))Finally, you can create a
Mockobject that implements the mock interface directly using themakeMockmethod. This can be useful when you want to access some mocking functionality without using the environment type.import zio.test.mock._ for { mockRandom <- MockRandom.makeMock(MockRandom.DefaultData) n <- mockRandom.nextInt } yield n
This can also be useful when you are creating a more complex environment to provide the implementation for mock services that you mix in.
- 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
AssertionValuekeeps track of a assertion and a value, existentially hiding the type.An
AssertionValuekeeps 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 CheckVariants extends AnyRef
- abstract class DefaultRunnableSpec extends RunnableSpec[String, ZTest[MockEnvironment, Any, 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[L, Either[TestFailure[E], TestSuccess[S]]]
An
ExecutedSpecis a spec that has been run to produce test results. - sealed trait ExecutionStrategy extends AnyRef
- final case class FailureDetails(fragment: AssertionValue, whole: AssertionValue, gen: Option[GenFailureDetails] = None) extends Product with Serializable
FailureDetailskeeps 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. - sealed trait GenFailureDetails extends AnyRef
GenFailureDetailskeeps 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[L, T, E, S] extends AbstractRunnableSpec
A
RunnableSpechas 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[+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. - final class TestAnnotation[V] extends AnyRef
A type of annotation.
- class TestAnnotationMap extends AnyRef
An annotation map keeps track of annotations of different types.
- trait TestAspect[+LowerR, -UpperR, +LowerE, -UpperE, +LowerS, -UpperS] extends AnyRef
A
TestAspectis an aspect that can be weaved into specs.A
TestAspectis 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
TestAspectPolyis aTestAspectthat is completely polymorphic, having no requirements on error or environment. - type TestExecutor[L, -T, +E, +S] = (Spec[L, T], ExecutionStrategy) => UIO[ExecutedSpec[L, E, S]]
A
TestExecutor[L, T, E, S]is capable of executing specs containing tests of typeT, annotated with labels of typeL, that may fail with anEor 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[L, -T, E, S](executor: TestExecutor[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 environmentRand may fail with an errorEor succeed with anS, using labels of typeL.A
TestRunner[R, E, L, S]encapsulates all the logic necessary to run specs that require an environmentRand may fail with an errorEor 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 TimeoutVariants extends AnyRef
- type ZSpec[-R, +E, +L, +S] = Spec[L, ZTest[R, E, 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. - implicit class ZSpecSyntax[R, E, L, S] extends AnyRef
Adds syntax for adding aspects.
Adds syntax for adding aspects.
test("foo") { assert(42, equalTo(42)) } @@ ignore
- type ZTest[-R, +E, +S] = ZIO[R, TestFailure[E], TestSuccess[S]]
A
ZTest[R, E, S]is an effectfully produced test that requires anRand may fail with anEor succeed with aS.
Value Members
- final def assert[A](value: => A, assertion: Assertion[A]): TestResult
Checks the assertion holds for the given value.
- 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
checkthat accepts four random variables.A version of
checkthat accepts four random variables.- Definition Classes
- CheckVariants
- 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
checkthat accepts three random variables.A version of
checkthat accepts three random variables.- Definition Classes
- CheckVariants
- 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
checkthat accepts two random variables.A version of
checkthat accepts two random variables.- Definition Classes
- CheckVariants
- 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.
Checks the test passes for "sufficient" numbers of samples from the given random variable.
- Definition Classes
- CheckVariants
- 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
checkAllthat accepts four random variables.A version of
checkAllthat accepts four random variables.- Definition Classes
- CheckVariants
- 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
checkAllthat accepts three random variables.A version of
checkAllthat accepts three random variables.- Definition Classes
- CheckVariants
- 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
checkAllthat accepts two random variables.A version of
checkAllthat accepts two random variables.- Definition Classes
- CheckVariants
- 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
Genthat comprehensively explore all possibilities in a given domain.- Definition Classes
- CheckVariants
- final def checkAllM[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[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkAllMthat accepts four random variables.A version of
checkAllMthat accepts four random variables.- Definition Classes
- CheckVariants
- final def checkAllM[R, E, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(test: (A, B, C) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkAllMthat accepts three random variables.A version of
checkAllMthat accepts three random variables.- Definition Classes
- CheckVariants
- final def checkAllM[R, E, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkAllMthat accepts two random variables.A version of
checkAllMthat accepts two random variables.- Definition Classes
- CheckVariants
- final def checkAllM[R, E, A](rv: Gen[R, A])(test: (A) => ZIO[R, E, TestResult]): ZIO[R, 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
Genthat comprehensively explore all possibilities in a given domain.- Definition Classes
- CheckVariants
- final def checkM[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[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkMthat accepts four random variables.A version of
checkMthat accepts four random variables.- Definition Classes
- CheckVariants
- final def checkM[R, E, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(test: (A, B, C) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkMthat accepts three random variables.A version of
checkMthat accepts three random variables.- Definition Classes
- CheckVariants
- final def checkM[R, E, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkMthat accepts two random variables.A version of
checkMthat accepts two random variables.- Definition Classes
- CheckVariants
- final def checkM[R, E, A](rv: Gen[R, A])(test: (A) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
Checks the effectual test passes for "sufficient" numbers of samples from the given random variable.
Checks the effectual test passes for "sufficient" numbers of samples from the given random variable.
- Definition Classes
- CheckVariants
- final def checkSome[R, A, B, C, D](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])(n: Int)(test: (A, B, C, D) => TestResult): ZIO[R, Nothing, TestResult]
A version of
checkSomethat accepts four random variables.A version of
checkSomethat accepts four random variables.- Definition Classes
- CheckVariants
- final def checkSome[R, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(n: Int)(test: (A, B, C) => TestResult): ZIO[R, Nothing, TestResult]
A version of
checkSomethat accepts three random variables.A version of
checkSomethat accepts three random variables.- Definition Classes
- CheckVariants
- final def checkSome[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(n: Int)(test: (A, B) => TestResult): ZIO[R, Nothing, TestResult]
A version of
checkSomethat accepts two random variables.A version of
checkSomethat accepts two random variables.- Definition Classes
- CheckVariants
- final def checkSome[R, A](rv: Gen[R, A])(n: Int)(test: (A) => TestResult): ZIO[R, Nothing, TestResult]
Checks the test passes for the specified number of samples from the given random variable.
Checks the test passes for the specified number of samples from the given random variable.
- Definition Classes
- CheckVariants
- final def checkSomeM[R, E, A, B, C, D](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D])(n: Int)(test: (A, B, C, D) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkSomeMthat accepts four random variables.A version of
checkSomeMthat accepts four random variables.- Definition Classes
- CheckVariants
- final def checkSomeM[R, E, A, B, C](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C])(n: Int)(test: (A, B, C) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkSomeMthat accepts three random variables.A version of
checkSomeMthat accepts three random variables.- Definition Classes
- CheckVariants
- final def checkSomeM[R, E, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(n: Int)(test: (A, B) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
A version of
checkSomeMthat accepts two random variables.A version of
checkSomeMthat accepts two random variables.- Definition Classes
- CheckVariants
- final def checkSomeM[R, E, A](rv: Gen[R, A])(n: Int)(test: (A) => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]
Checks the effectual test passes for the specified number of samples from the given random variable.
Checks the effectual test passes for the specified number of samples from the given random variable.
- Definition Classes
- CheckVariants
- val defaultTestRunner: TestRunner[String, ZTest[MockEnvironment, Any, Any], Any, Any]
- final def fail[E](cause: Cause[E]): ZTest[Any, E, Nothing]
Creates a failed test result with the specified runtime cause.
- final val ignore: 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[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, 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.
- object Assertion
- object AssertionValue
- object BoolAlgebra extends Serializable
- object DefaultTestReporter
- object DefaultTestRunner extends TestRunner[String, ZTest[MockEnvironment, Any, Any], Any, Any]
A
Runnerthat provides a default testable environment. - object ExecutionStrategy
- object Gen extends GenZIO with Serializable
- object GenFailureDetails
- object RenderedResult extends Serializable
- object Sample extends Serializable
- object Sized
- object Spec extends Serializable
- object TestAnnotation
- object TestAnnotationMap
- object TestAspect extends TimeoutVariants
- object TestExecutor
- object TestFailure
- object TestLogger
- object TestPlatform
TestPlatformprovides information about the platform tests are being run on to enable platform specific test configuration. - object TestReporter
- object TestSuccess