Packages

  • package root
    Definition Classes
    root
  • package zio
    Definition Classes
    root
  • package test

    _ZIO Test_ is a featherweight testing library for effectful programs.

    _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.test.environment.Live
    import zio.clock.nanoTime
    import Assertion.isGreaterThan
    
    object MyTest extends DefaultRunnableSpec {
      def spec = suite("clock")(
        testM("time is non-zero") {
          assertM(Live.live(nanoTime))(isGreaterThan(0))
        }
      )
    }
    Definition Classes
    zio
  • 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 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.

    Definition Classes
    test
  • object TestClock extends Serializable

    TestClock makes it easy to deterministically and efficiently test effects involving the passage of time.

    TestClock makes it easy to deterministically and efficiently test effects involving the passage of time.

    Instead of waiting for actual time to pass, sleep and methods implemented in terms of it schedule effects to take place at a given clock time. Users can adjust the clock time using the adjust and setTime methods, and all effects scheduled to take place on or before that time will automatically be run in order.

    For example, here is how we can test ZIO#timeout using TestClock:

    import zio.ZIO
    import zio.duration._
    import zio.test.environment.TestClock
    
    for {
      fiber  <- ZIO.sleep(5.minutes).timeout(1.minute).fork
      _      <- TestClock.adjust(1.minute)
      result <- fiber.join
    } yield result == None

    Note how we forked the fiber that sleep was invoked on. Calls to sleep and methods derived from it will semantically block until the time is set to on or after the time they are scheduled to run. If we didn't fork the fiber on which we called sleep we would never get to set the time on the line below. Thus, a useful pattern when using TestClock is to fork the effect being tested, then adjust the clock time, and finally verify that the expected effects have been performed.

    For example, here is how we can test an effect that recurs with a fixed delay:

    import zio.Queue
    import zio.duration._
    import zio.test.environment.TestClock
    
    for {
      q <- Queue.unbounded[Unit]
      _ <- q.offer(()).delay(60.minutes).forever.fork
      a <- q.poll.map(_.isEmpty)
      _ <- TestClock.adjust(60.minutes)
      b <- q.take.as(true)
      c <- q.poll.map(_.isEmpty)
      _ <- TestClock.adjust(60.minutes)
      d <- q.take.as(true)
      e <- q.poll.map(_.isEmpty)
    } yield a && b && c && d && e

    Here we verify that no effect is performed before the recurrence period, that an effect is performed after the recurrence period, and that the effect is performed exactly once. The key thing to note here is that after each recurrence the next recurrence is scheduled to occur at the appropriate time in the future, so when we adjust the clock by 60 minutes exactly one value is placed in the queue, and when we adjust the clock by another 60 minutes exactly one more value is placed in the queue.

    Definition Classes
    environment
  • Data
  • Service
  • Sleep
  • SuspendedWarningData
  • Test
  • WarningData

final case class Test(clockState: Ref[Data], live: Live.Service, annotations: Annotations.Service, warningState: RefM[WarningData], suspendedWarningState: RefM[SuspendedWarningData]) extends clock.Clock.Service with Service with Product with Serializable

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Test
  2. Product
  3. Equals
  4. Service
  5. Restorable
  6. Service
  7. Serializable
  8. Serializable
  9. AnyRef
  10. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Test(clockState: Ref[Data], live: Live.Service, annotations: Annotations.Service, warningState: RefM[WarningData], suspendedWarningState: RefM[SuspendedWarningData])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def adjust(duration: Duration): UIO[Unit]

    Increments the current clock time by the specified duration.

    Increments the current clock time by the specified duration. Any effects that were scheduled to occur on or before the new time will be run in order.

    Definition Classes
    TestService
  5. val annotations: Annotations.Service
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. val clockState: Ref[Data]
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  9. def currentDateTime: UIO[OffsetDateTime]

    Returns the current clock time as an OffsetDateTime.

    Returns the current clock time as an OffsetDateTime.

    Definition Classes
    Test → Service
  10. def currentTime(unit: TimeUnit): UIO[Long]

    Returns the current clock time in the specified time unit.

    Returns the current clock time in the specified time unit.

    Definition Classes
    Test → Service
  11. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def instant: UIO[Instant]
    Definition Classes
    Service
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. val live: Live.Service
  17. def localDateTime: IO[DateTimeException, LocalDateTime]
    Definition Classes
    Service
  18. lazy val nanoTime: UIO[Long]

    Returns the current clock time in nanoseconds.

    Returns the current clock time in nanoseconds.

    Definition Classes
    Test → Service
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. val save: UIO[UIO[Unit]]

    Saves the TestClock's current state in an effect which, when run, will restore the TestClock state to the saved state

    Saves the TestClock's current state in an effect which, when run, will restore the TestClock state to the saved state

    Definition Classes
    TestRestorable
  23. def setDateTime(dateTime: OffsetDateTime): UIO[Unit]

    Sets the current clock time to the specified OffsetDateTime.

    Sets the current clock time to the specified OffsetDateTime. Any effects that were scheduled to occur on or before the new time will be run in order.

    Definition Classes
    TestService
  24. def setTime(duration: Duration): UIO[Unit]

    Sets the current clock time to the specified time in terms of duration since the epoch.

    Sets the current clock time to the specified time in terms of duration since the epoch. Any effects that were scheduled to occur on or before the new time will immediately be run in order.

    Definition Classes
    TestService
  25. def setTimeZone(zone: ZoneId): UIO[Unit]

    Sets the time zone to the specified time zone.

    Sets the time zone to the specified time zone. The clock time in terms of nanoseconds since the epoch will not be adjusted and no scheduled effects will be run as a result of this method.

    Definition Classes
    TestService
  26. def sleep(duration: Duration): UIO[Unit]

    Semantically blocks the current fiber until the clock time is equal to or greater than the specified duration.

    Semantically blocks the current fiber until the clock time is equal to or greater than the specified duration. Once the clock time is adjusted to on or after the duration, the fiber will automatically be resumed.

    Definition Classes
    Test → Service
  27. lazy val sleeps: UIO[List[Duration]]

    Returns a list of the times at which all queued effects are scheduled to resume.

    Returns a list of the times at which all queued effects are scheduled to resume.

    Definition Classes
    TestService
  28. def supervisedFibers: UIO[SortedSet[Fiber.Runtime[Any, Any]]]

    Returns a set of all fibers in this test.

  29. val suspendedWarningState: RefM[SuspendedWarningData]
  30. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  31. lazy val timeZone: UIO[ZoneId]

    Returns the time zone.

    Returns the time zone.

    Definition Classes
    TestService
  32. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  35. val warningState: RefM[WarningData]

Inherited from Product

Inherited from Equals

Inherited from Service

Inherited from Restorable

Inherited from clock.Clock.Service

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped