TestSystem

object TestSystem extends Serializable

TestSystem supports deterministic testing of effects involving system properties. Internally, TestSystem maintains mappings of environment variables and system properties that can be set and accessed. No actual environment variables or system properties will be accessed or set as a result of these actions.

import zio.system
import zio.test.environment.TestSystem

for {
 _      <- TestSystem.putProperty("java.vm.name", "VM")
 result <- system.property("java.vm.name")
} yield result == Some("VM")
class Object
trait Matchable
class Any

Type members

Classlikes

final case class Data(properties: Map[String, String], envs: Map[String, String], lineSeparator: String)

The state of the TestSystem.

The state of the TestSystem.

trait Service extends Restorable
final case class Test(systemState: Ref[Data]) extends Service with Service

Value members

Concrete methods

def clearEnv(variable: => String): URIO[TestSystem, Unit]

Accesses a TestSystem instance in the environment and clears the mapping of environment variables.

Accesses a TestSystem instance in the environment and clears the mapping of environment variables.

Accesses a TestSystem instance in the environment and clears the mapping of system properties.

Accesses a TestSystem instance in the environment and clears the mapping of system properties.

def live(data: Data): Layer[Nothing, System & TestSystem]

Constructs a new TestSystem with the specified initial state. This can be useful for providing the required environment to an effect that requires a Console, such as with ZIO#provide.

Constructs a new TestSystem with the specified initial state. This can be useful for providing the required environment to an effect that requires a Console, such as with ZIO#provide.

def putEnv(name: => String, value: => String): URIO[TestSystem, Unit]

Accesses a TestSystem instance in the environment and adds the specified name and value to the mapping of environment variables.

Accesses a TestSystem instance in the environment and adds the specified name and value to the mapping of environment variables.

def putProperty(name: => String, value: => String): URIO[TestSystem, Unit]

Accesses a TestSystem instance in the environment and adds the specified name and value to the mapping of system properties.

Accesses a TestSystem instance in the environment and adds the specified name and value to the mapping of system properties.

Accesses a TestSystem instance in the environment and sets the line separator to the specified value.

Accesses a TestSystem instance in the environment and sets the line separator to the specified value.

Concrete fields

The default initial state of the TestSystem with no environment variable or system property mappings and the system line separator set to the new line character.

The default initial state of the TestSystem with no environment variable or system property mappings and the system line separator set to the new line character.

val default: Layer[Nothing, System & TestSystem]
val save: ZIO[TestSystem, Nothing, UIO[Unit]]

Accesses a TestSystem instance in the environment and saves the system state in an effect which, when run, will restore the TestSystem to the saved state

Accesses a TestSystem instance in the environment and saves the system state in an effect which, when run, will restore the TestSystem to the saved state