Package

zio

test

Permalink

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 {
  def spec = suite("clock")(
    testM("time is non-zero") {
      assertM(nanoTime)(isGreaterThan(0))
    }
  )
}
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. test
  2. CompileVariants
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractRunnableSpec extends AnyRef

    Permalink
    Annotations
    @EnableReflectiveInstantiation()
  2. type Annotated[+A] = (A, TestAnnotationMap)

    Permalink

    An Annotated[A] contains a value of type A along with zero or more test annotations.

  3. type Annotations = Has[Service]

    Permalink
  4. type AssertResult = BoolAlgebraM[Any, Nothing, AssertionValue]

    Permalink
  5. final class Assertion[-A] extends (⇒ A) ⇒ AssertResult

    Permalink

    An Assertion[A] is capable of producing assertion results on an A.

    An Assertion[A] is capable of producing assertion results on an A. As a proposition, assertions compose using logical conjunction and disjunction, and can be negated.

  6. sealed trait AssertionValue extends AnyRef

    Permalink

    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.

  7. trait AssertionVariants extends AnyRef

    Permalink
  8. sealed trait BoolAlgebra[+A] extends Product with Serializable

    Permalink

    A BoolAlgebra[A] is a description of logical operations on values of type A.

  9. final case class BoolAlgebraM[-R, +E, +A](run: ZIO[R, E, BoolAlgebra[A]]) extends Product with Serializable

    Permalink
  10. trait CompileVariants extends AnyRef

    Permalink
  11. trait DefaultRunnableSpec extends AbstractRunnableSpec with RunnableSpec[test.environment.TestEnvironment, Any]

    Permalink

    A default runnable spec that provides testable versions of all of the modules in ZIO (Clock, Random, etc).

  12. sealed trait Eql[A, B] extends AnyRef

    Permalink

    A value of type Eql[A, B] provides implicit evidence that two values with types A and B could potentially be equal, that is, that A is a subtype of B or B is a subtype of A.

    A value of type Eql[A, B] provides implicit evidence that two values with types A and B could potentially be equal, that is, that A is a subtype of B or B is a subtype of A.

    Annotations
    @implicitNotFound( ... )
  13. type ExecutedResult[+E] = Either[TestFailure[E], TestSuccess]

    Permalink

    An ExecutedResult[E] is either a TestSuccess or a TestFailure[E].

  14. type ExecutedSpec[+E] = Spec[Any, Nothing, ExecutedResult[E]]

    Permalink

    An ExecutedSpec is a spec that has been run to produce test results.

  15. sealed trait ExecutionStrategy extends AnyRef

    Permalink
  16. final case class FailureDetails(assertion: ::[AssertionValue], gen: Option[GenFailureDetails] = None) extends Product with Serializable

    Permalink

    FailureDetails keeps track of details relevant to failures.

  17. trait FunctionVariants extends AnyRef

    Permalink
  18. final case class Gen[-R, +A](sample: ZStream[R, Nothing, Sample[R, A]]) extends Product with Serializable

    Permalink

    A Gen[R, A] represents a generator of values of type A, which requires an environment R.

    A Gen[R, A] represents a generator of values of type A, which requires an environment R. Generators may be random or deterministic.

  19. sealed trait GenFailureDetails extends AnyRef

    Permalink

    GenFailureDetails keeps track of relevant information related to a failure in a generative test.

  20. trait GenZIO extends AnyRef

    Permalink
  21. case class RenderedResult[T](caseType: CaseType, label: String, status: Status, offset: Int, rendered: Seq[T]) extends Product with Serializable

    Permalink
  22. trait RunnableSpec[R <: Has[_], E] extends AbstractRunnableSpec

    Permalink

    A RunnableSpec has a main function and can be run by the JVM / Scala.js.

  23. final case class Sample[-R, +A](value: A, shrink: ZStream[R, Nothing, Sample[R, A]]) extends Product with Serializable

    Permalink

    A sample is a single observation from a random variable, together with a tree of "shrinkings" used for minimization of "large" failures.

  24. type Sized = Has[Service]

    Permalink
  25. final case class Spec[-R, +E, +T](caseValue: SpecCase[R, E, T, Spec[R, E, T]]) extends Product with Serializable

    Permalink

    A Spec[R, E, T] is the backbone of _ZIO Test_.

    A Spec[R, E, T] is the backbone of _ZIO Test_. Every spec is either a suite, which contains other specs, or a test of type T. All specs require an environment of type R and may potentially fail with an error of type E.

  26. final case class Summary(success: Int, fail: Int, ignore: Int, summary: String) extends Product with Serializable

    Permalink
  27. final class TestAnnotation[V] extends Serializable

    Permalink

    A type of annotation.

  28. final class TestAnnotationMap extends AnyRef

    Permalink

    An annotation map keeps track of annotations of different types.

  29. sealed trait TestAnnotationRenderer extends AnyRef

    Permalink

    A TestAnnotationRenderer knows how to render test annotations.

  30. final case class TestArgs(testSearchTerms: List[String], tagSearchTerms: List[String], testTaskPolicy: Option[String]) extends Product with Serializable

    Permalink
  31. trait TestAspect[+LowerR, -UpperR, +LowerE, -UpperE] extends AnyRef

    Permalink

    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.

  32. type TestAspectAtLeastR[R] = TestAspect[Nothing, R, Nothing, Any]

    Permalink

    A TestAspectAtLeast[R] is a TestAspect that requires at least an R in its environment.

  33. type TestAspectPoly = TestAspect[Nothing, Any, Nothing, Any]

    Permalink

    A TestAspectPoly is a TestAspect that is completely polymorphic, having no requirements on error or environment.

  34. trait TestExecutor[+R <: Has[_], E] extends AnyRef

    Permalink

    A TestExecutor[R, E] is capable of executing specs that require an environment R and may fail with an E.

  35. sealed trait TestFailure[+E] extends AnyRef

    Permalink
  36. type TestLogger = Has[Service]

    Permalink
  37. type TestReporter[-E] = (Duration, ExecutedSpec[E]) ⇒ URIO[TestLogger, Unit]

    Permalink

    A TestReporter[E] is capable of reporting test results with error type E.

  38. type TestResult = BoolAlgebraM[Any, Nothing, FailureDetails]

    Permalink
  39. final case class TestRunner[R <: Has[_], E](executor: TestExecutor[R, E], platform: Platform = ..., reporter: TestReporter[E] = ..., bootstrap: Layer[Nothing, TestLogger with Clock] = ...) extends Product with Serializable

    Permalink

    A TestRunner[R, E] encapsulates all the logic necessary to run specs that require an environment R and may fail with an error E.

    A TestRunner[R, E] encapsulates all the logic necessary to run specs that require an environment R and may fail with an error E. Test runners require a test executor, a platform, and a reporter.

  40. sealed trait TestSuccess extends AnyRef

    Permalink
  41. final case class TestTimeoutException(message: String) extends Throwable with Product with Serializable

    Permalink
  42. trait TimeVariants extends AnyRef

    Permalink
  43. trait TimeoutVariants extends AnyRef

    Permalink
  44. type ZSpec[-R, +E] = Spec[R, TestFailure[E], TestSuccess]

    Permalink

    A ZSpec[R, E] is the canonical spec for testing ZIO programs.

    A ZSpec[R, E] is the canonical spec for testing ZIO programs. The spec's test type is a ZIO effect that requires an R and might fail with an E.

  45. type ZTest[-R, +E] = ZIO[R, TestFailure[E], TestSuccess]

    Permalink

    A ZTest[R, E] is an effectfully produced test that requires an R and may fail with an E.

  46. type ZTestEnv = TestClock with TestConsole with TestRandom with TestSystem

    Permalink

    A ZRTestEnv is an alias for all ZIO provided Restorable TestEnvironment objects

Value Members

  1. object Annotations extends Serializable

    Permalink

    The Annotations trait provides access to an annotation map that tests can add arbitrary annotations to.

    The Annotations trait provides access to an annotation map that tests can add arbitrary annotations to. Each annotation consists of a string identifier, an initial value, and a function for combining two values. Annotations form monoids and you can think of Annotations as a more structured logging service or as a super polymorphic version of the writer monad effect.

  2. object Assertion extends AssertionVariants

    Permalink
  3. object AssertionValue

    Permalink
  4. object BoolAlgebra extends Serializable

    Permalink
  5. object BoolAlgebraM extends Serializable

    Permalink
  6. object CheckVariants

    Permalink
  7. object DefaultTestReporter

    Permalink
  8. object Eql

    Permalink
  9. object ExecutionStrategy

    Permalink
  10. object FailureRenderer

    Permalink
  11. object Gen extends GenZIO with FunctionVariants with TimeVariants with Serializable

    Permalink
  12. object GenFailureDetails

    Permalink
  13. object RenderedResult extends Serializable

    Permalink
  14. object Sample extends Serializable

    Permalink
  15. object Sized extends Serializable

    Permalink
  16. object Spec extends Serializable

    Permalink
  17. object SummaryBuilder

    Permalink
  18. object TestAnnotation extends Serializable

    Permalink
  19. object TestAnnotationMap

    Permalink
  20. object TestAnnotationRenderer

    Permalink
  21. object TestArgs extends Serializable

    Permalink
  22. object TestAspect extends TimeoutVariants

    Permalink
  23. object TestExecutor

    Permalink
  24. object TestFailure

    Permalink
  25. object TestLogger extends Serializable

    Permalink
  26. object TestPlatform

    Permalink

    TestPlatform provides information about the platform tests are being run on to enable platform specific test configuration.

  27. object TestReporter

    Permalink
  28. object TestSuccess

    Permalink
  29. object TestVersion

    Permalink

    TestVersion provides information about the Scala version tests are being run on to enable platform specific test configuration.

  30. object ZTest extends Serializable

    Permalink
  31. def assert[A](value: ⇒ A)(assertion: Assertion[A]): TestResult

    Permalink

    Checks the assertion holds for the given value.

  32. val assertCompletes: TestResult

    Permalink

    Asserts that the given test was completed.

  33. def assertM[R, E, A](value: ZIO[R, E, A])(assertion: Assertion[A]): ZIO[R, E, TestResult]

    Permalink

    Checks the assertion holds for the given effectfully-computed value.

  34. def check[R, A, B, C, D, F, G](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F], rv6: Gen[R, G])(test: (A, B, C, D, F, G) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    A version of check that accepts six random variables.

  35. def check[R, A, B, C, D, F](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F])(test: (A, B, C, D, F) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    A version of check that accepts five random variables.

  36. 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]

    Permalink

    A version of check that accepts four random variables.

  37. 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]

    Permalink

    A version of check that accepts three random variables.

  38. def check[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    A version of check that accepts two random variables.

  39. def check[R, A](rv: Gen[R, A])(test: (A) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    Checks the test passes for "sufficient" numbers of samples from the given random variable.

  40. def checkAll[R, A, B, C, D, F, G](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F], rv6: Gen[R, G])(test: (A, B, C, D, F, G) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    A version of checkAll that accepts six random variables.

  41. def checkAll[R, A, B, C, D, F](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F])(test: (A, B, C, D, F) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    A version of checkAll that accepts five random variables.

  42. 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]

    Permalink

    A version of checkAll that accepts four random variables.

  43. 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]

    Permalink

    A version of checkAll that accepts three random variables.

  44. def checkAll[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    A version of checkAll that accepts two random variables.

  45. def checkAll[R, A](rv: Gen[R, A])(test: (A) ⇒ TestResult): ZIO[R, Nothing, TestResult]

    Permalink

    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.

  46. def checkAllM[R, R1 <: R, E, A, B, C, D, F, G](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F], rv6: Gen[R, G])(test: (A, B, C, D, F, G) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

    Permalink

    A version of checkAllM that accepts six random variables.

  47. def checkAllM[R, R1 <: R, E, A, B, C, D, F](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F])(test: (A, B, C, D, F) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

    Permalink

    A version of checkAllM that accepts five random variables.

  48. 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]

    Permalink

    A version of checkAllM that accepts four random variables.

  49. 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]

    Permalink

    A version of checkAllM that accepts three random variables.

  50. 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]

    Permalink

    A version of checkAllM that accepts two random variables.

  51. def checkAllM[R, R1 <: R, E, A](rv: Gen[R, A])(test: (A) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

    Permalink

    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.

  52. def checkM[R, R1 <: R, E, A, B, C, D, F, G](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F], rv6: Gen[R, G])(test: (A, B, C, D, F, G) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

    Permalink

    A version of checkM that accepts six random variables.

  53. def checkM[R, R1 <: R, E, A, B, C, D, F](rv1: Gen[R, A], rv2: Gen[R, B], rv3: Gen[R, C], rv4: Gen[R, D], rv5: Gen[R, F])(test: (A, B, C, D, F) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

    Permalink

    A version of checkM that accepts five random variables.

  54. 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]

    Permalink

    A version of checkM that accepts four random variables.

  55. 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]

    Permalink

    A version of checkM that accepts three random variables.

  56. 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]

    Permalink

    A version of checkM that accepts two random variables.

  57. def checkM[R, R1 <: R, E, A](rv: Gen[R, A])(test: (A) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

    Permalink

    Checks the effectual test passes for "sufficient" numbers of samples from the given random variable.

  58. def checkN(n: Int): CheckN

    Permalink

    Checks the test passes for the specified number of samples from the given random variable.

  59. def checkNM(n: Int): CheckNM

    Permalink

    Checks the effectual test passes for the specified number of samples from the given random variable.

  60. val defaultTestRunner: TestRunner[test.environment.TestEnvironment, Any]

    Permalink

    A Runner that provides a default testable environment.

  61. package environment

    Permalink

    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 RunnableSpec a TestEnvironment 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 the TestEnvironment to your program.

    import zio.test.environment._
    
    myProgram.provideLayer(testEnvironment)

    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 the live 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 as DefaultData.

    import zio.test.environment._
    
    myProgram.provideM(TestConsole.make(TestConsole.DefaultData))

    Finally, you can create a Test object that implements the test interface directly using the makeTest 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.

  62. def failed[E](cause: Cause[E]): ZIO[Any, TestFailure[E], Nothing]

    Permalink

    Creates a failed test result with the specified runtime cause.

  63. val ignored: ZIO[Any, Nothing, TestSuccess]

    Permalink

    Creates an ignored test result.

  64. package mock

    Permalink
  65. def platformSpecific[R, E, A](js: ⇒ A, jvm: ⇒ A)(f: (A) ⇒ ZTest[R, E]): ZTest[R, E]

    Permalink

    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.

  66. package poly

    Permalink
  67. package reflect

    Permalink
  68. def suite[R, E, T](label: String)(specs: Spec[R, E, T]*): Spec[R, E, T]

    Permalink

    Builds a suite containing a number of other specs.

  69. def test(label: String)(assertion: ⇒ TestResult): ZSpec[Any, Nothing]

    Permalink

    Builds a spec with a single pure test.

  70. def testM[R, E](label: String)(assertion: ⇒ ZIO[R, E, TestResult]): ZSpec[R, E]

    Permalink

    Builds a spec with a single effectful test.

  71. final macro def typeCheck(code: String): UIO[Either[String, Unit]]

    Permalink

    Returns either Right if the specified string type checks as valid Scala code or Left with an error message otherwise.

    Returns either Right if the specified string type checks as valid Scala code or Left 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
  72. def versionSpecific[R, E, A](dotty: ⇒ A, scala2: ⇒ A)(f: (A) ⇒ ZTest[R, E]): ZTest[R, E]

    Permalink

    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.

Inherited from CompileVariants

Inherited from AnyRef

Inherited from Any

Ungrouped