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 {
  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 AssertResult = BoolAlgebra[AssertionValue]

    Permalink
  3. 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 conjuction and disjunction, and can be negated.

  4. 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.

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

    Permalink

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

  6. trait CompileVariants extends AnyRef

    Permalink
  7. abstract class DefaultRunnableSpec extends RunnableSpec[TestEnvironment, String, Any, Any, Any]

    Permalink

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

  8. type ExecutedSpec[+L, +E, +S] = Spec[Any, Nothing, L, Either[TestFailure[E], TestSuccess[S]]]

    Permalink

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

  9. sealed trait ExecutionStrategy extends AnyRef

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

    Permalink

    FailureDetails keeps track of details relevant to failures.

  11. trait FunctionVariants extends AnyRef

    Permalink
  12. 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.

  13. sealed trait GenFailureDetails extends AnyRef

    Permalink

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

  14. trait GenZIO extends AnyRef

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

    Permalink
  16. abstract class RunnableSpec[R, L, T, E, S] extends AbstractRunnableSpec

    Permalink

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

  17. 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.

  18. trait Sized extends AnyRef

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

    Permalink

    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 type T. All specs are annotated with labels of type L, require an environment of type R and may potentially fail with an error of type E.

  20. final class TestAnnotation[V] extends AnyRef

    Permalink

    A type of annotation.

  21. class TestAnnotationMap extends AnyRef

    Permalink

    An annotation map keeps track of annotations of different types.

  22. case class TestArgs(testSearchTerms: List[String]) extends Product with Serializable

    Permalink
  23. trait TestAspect[+LowerR, -UpperR, +LowerE, -UpperE, +LowerS, -UpperS] 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, error, or success type.

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

    Permalink

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

  25. type TestExecutor[+R, L, -T, E, +S] = (ZSpec[R, E, L, T], ExecutionStrategy) ⇒ UIO[ExecutedSpec[L, E, S]]

    Permalink

    A TestExecutor[R, L, T, E, S] is capable of executing specs containing tests of type T, annotated with labels of type L, that require an environment R and may fail with an E or succeed with a S.

  26. sealed trait TestFailure[+E] extends AnyRef

    Permalink
  27. trait TestLogger extends AnyRef

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

    Permalink

    A TestReporter[L, E, S] is capable of reporting test results annotated with labels L, error type E, and success type S.

  29. type TestResult = BoolAlgebra[FailureDetails]

    Permalink
  30. case class TestRunner[R, L, -T, E, S](executor: TestExecutor[R, L, T, E, S], platform: Platform = ..., reporter: TestReporter[L, E, S] = DefaultTestReporter()) extends Product with Serializable

    Permalink

    A TestRunner[R, E, L, S] encapsulates all the logic necessary to run specs that require an environment R and may fail with an error E or succeed with an S, using labels of type L.

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

  31. sealed trait TestSuccess[+S] extends AnyRef

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

    Permalink
  33. trait TimeVariants extends AnyRef

    Permalink
  34. trait TimeoutVariants extends AnyRef

    Permalink
  35. type ZSpec[-R, +E, +L, +S] = Spec[R, TestFailure[E], L, TestSuccess[S]]

    Permalink

    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 an R, might fail with an E, might succeed with an S, and whose nodes are annotated with labels L.

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

    Permalink

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

Value Members

  1. object Assertion

    Permalink
  2. object AssertionValue

    Permalink
  3. object BoolAlgebra extends Serializable

    Permalink
  4. object CheckVariants

    Permalink
  5. object DefaultTestReporter

    Permalink
  6. object DefaultTestRunner extends TestRunner[TestEnvironment, String, Any, Any, Any]

    Permalink

    A Runner that provides a default testable environment.

  7. object ExecutionStrategy

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

    Permalink
  9. object GenFailureDetails

    Permalink
  10. object RenderedResult extends Serializable

    Permalink
  11. object Sample extends Serializable

    Permalink
  12. object Sized

    Permalink
  13. object Spec extends Serializable

    Permalink
  14. object SummaryBuilder

    Permalink
  15. object TestAnnotation

    Permalink
  16. object TestAnnotationMap

    Permalink
  17. object TestArgs extends Serializable

    Permalink
  18. object TestAspect extends TimeoutVariants

    Permalink
  19. object TestExecutor

    Permalink
  20. object TestFailure

    Permalink
  21. object TestLogger

    Permalink
  22. object TestPlatform

    Permalink

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

  23. object TestReporter

    Permalink
  24. object TestSuccess

    Permalink
  25. object TestVersion

    Permalink

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

  26. final def assert[A](value: ⇒ A, assertion: Assertion[A]): TestResult

    Permalink

    Checks the assertion holds for the given value.

  27. final val assertCompletes: TestResult

    Permalink

    Asserts that the given test was completed.

  28. final 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.

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

    Permalink

    A version of check that accepts four random variables.

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

    Permalink

    A version of check that accepts three random variables.

  31. final 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.

  32. final 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.

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

    Permalink

    A version of checkAll that accepts four random variables.

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

    Permalink

    A version of checkAll that accepts three random variables.

  35. final 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.

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

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

    Permalink

    A version of checkAllM that accepts four random variables.

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

    Permalink

    A version of checkAllM that accepts three random variables.

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

    Permalink

    A version of checkAllM that accepts two random variables.

  40. final 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.

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

    Permalink

    A version of checkM that accepts four random variables.

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

    Permalink

    A version of checkM that accepts three random variables.

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

    Permalink

    A version of checkM that accepts two random variables.

  44. final 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.

  45. final def checkSome(n: Int): CheckSome

    Permalink

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

  46. final def checkSomeM(n: Int): CheckSomeM

    Permalink

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

  47. 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 DefaultRunnableSpec 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.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 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.

  48. final def failed[E](cause: Cause[E]): ZTest[Any, E, Nothing]

    Permalink

    Creates a failed test result with the specified runtime cause.

  49. final val ignored: ZTest[Any, Nothing, Nothing]

    Permalink

    Creates an ignored test result.

  50. package mock

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

    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.

  52. package reflect

    Permalink
  53. final def suite[R, E, L, T](label: L)(specs: Spec[R, E, L, T]*): Spec[R, E, L, T]

    Permalink

    Builds a suite containing a number of other specs.

  54. final def test[L](label: L)(assertion: ⇒ TestResult): ZSpec[Any, Nothing, L, Unit]

    Permalink

    Builds a spec with a single pure test.

  55. final def testM[R, E, L](label: L)(assertion: ⇒ ZIO[R, E, TestResult]): ZSpec[R, E, L, Unit]

    Permalink

    Builds a spec with a single effectful test.

  56. 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
  57. final def versionSpecific[R, E, A, S](dotty: ⇒ A, scala2: ⇒ A)(f: (A) ⇒ ZTest[R, E, S]): ZTest[R, E, S]

    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