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)) } ) }
- Alphabetic
- By Inheritance
- test
- CompileVariants
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
abstract
class
AbstractRunnableSpec extends AnyRef
- Annotations
- @EnableReflectiveInstantiation()
-
type
Annotated[+A] = (A, TestAnnotationMap)
An
Annotated[A]
contains a value of typeA
along with zero or more test annotations. - type Annotations = Has[Service]
- type AssertResult = BoolAlgebra[AssertionValue]
- type AssertResultM = BoolAlgebraM[Any, Nothing, AssertionValue]
-
final
class
Assertion[-A] extends (⇒ A) ⇒ AssertResult with AssertionM[A]
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 conjunction and disjunction, and can be negated. - sealed trait AssertionData extends AnyRef
-
trait
AssertionM[-A] extends AnyRef
An
AssertionM[A]
is capable of producing assertion results on anA
.An
AssertionM[A]
is capable of producing assertion results on anA
. As a proposition, assertions compose using logical conjunction and disjunction, and can be negated. - sealed trait AssertionMData extends AnyRef
-
sealed
trait
AssertionValue extends AnyRef
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. - trait AssertionVariants extends AnyRef
-
sealed
trait
BoolAlgebra[+A] extends Product with Serializable
A
BoolAlgebra[A]
is a description of logical operations on values of typeA
. - final case class BoolAlgebraM[-R, +E, +A](run: ZIO[R, E, BoolAlgebra[A]]) extends Product with Serializable
- trait CompileVariants extends AnyRef
-
trait
DefaultRunnableSpec extends AbstractRunnableSpec with RunnableSpec[test.environment.TestEnvironment, Any]
A default runnable spec that provides testable versions of all of the modules in ZIO (Clock, Random, etc).
-
sealed
trait
Eql[A, B] extends AnyRef
A value of type
Eql[A, B]
provides implicit evidence that two values with typesA
andB
could potentially be equal, that is, thatA
is a subtype ofB
orB
is a subtype ofA
.A value of type
Eql[A, B]
provides implicit evidence that two values with typesA
andB
could potentially be equal, that is, thatA
is a subtype ofB
orB
is a subtype ofA
.- Annotations
- @implicitNotFound( ... )
-
type
ExecutedResult[+E] = Either[TestFailure[E], TestSuccess]
An
ExecutedResult[E] is either a
TestSuccessor a
TestFailure[E].
-
type
ExecutedSpec[+E] = Spec[Any, Nothing, ExecutedResult[E]]
An
ExecutedSpec
is a spec that has been run to produce test results. -
final
case class
FailureDetails(assertion: ::[AssertionValue], gen: Option[GenFailureDetails] = None) extends Product with Serializable
FailureDetails
keeps track of details relevant to failures. - trait FunctionVariants extends AnyRef
-
final
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
GenFailureDetails
keeps track of relevant information related to a failure in a generative test. - trait GenZIO extends AnyRef
- case class RenderedResult[T](caseType: CaseType, label: String, status: Status, offset: Int, rendered: Seq[T]) extends Product with Serializable
-
trait
RunnableSpec[R <: Has[_], E] extends AbstractRunnableSpec
A
RunnableSpec
has 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.
- type Sized = Has[Service]
-
final
case class
Spec[-R, +E, +T](caseValue: SpecCase[R, E, T, Spec[R, E, T]]) extends Product with Serializable
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 typeT
. All specs require an environment of typeR
and may potentially fail with an error of typeE
. - final case class Summary(success: Int, fail: Int, ignore: Int, summary: String) extends Product with Serializable
-
final
class
TestAnnotation[V] extends Serializable
A type of annotation.
-
final
class
TestAnnotationMap extends AnyRef
An annotation map keeps track of annotations of different types.
-
sealed
trait
TestAnnotationRenderer extends AnyRef
A
TestAnnotationRenderer
knows how to render test annotations. - final case class TestArgs(testSearchTerms: List[String], tagSearchTerms: List[String], testTaskPolicy: Option[String]) extends Product with Serializable
-
trait
TestAspect[+LowerR, -UpperR, +LowerE, -UpperE] extends AnyRef
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. -
type
TestAspectAtLeastR[R] = TestAspect[Nothing, R, Nothing, Any]
A
TestAspectAtLeast[R]
is aTestAspect
that requires at least anR
in its environment. -
type
TestAspectPoly = TestAspect[Nothing, Any, Nothing, Any]
A
TestAspectPoly
is aTestAspect
that is completely polymorphic, having no requirements on error or environment. -
trait
TestExecutor[+R <: Has[_], E] extends AnyRef
A
TestExecutor[R, E]
is capable of executing specs that require an environmentR
and may fail with anE
. - sealed trait TestFailure[+E] extends AnyRef
- type TestLogger = Has[Service]
-
type
TestReporter[-E] = (Duration, ExecutedSpec[E]) ⇒ URIO[TestLogger, Unit]
A
TestReporter[E]
is capable of reporting test results with error typeE
. - type TestResult = BoolAlgebra[FailureDetails]
-
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
A
TestRunner[R, E]
encapsulates all the logic necessary to run specs that require an environmentR
and may fail with an errorE
.A
TestRunner[R, E]
encapsulates all the logic necessary to run specs that require an environmentR
and may fail with an errorE
. Test runners require a test executor, a platform, and a reporter. - sealed trait TestSuccess extends AnyRef
- final case class TestTimeoutException(message: String) extends Throwable with Product with Serializable
- trait TimeVariants extends AnyRef
- trait TimeoutVariants extends AnyRef
-
type
ZSpec[-R, +E] = Spec[R, TestFailure[E], TestSuccess]
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 anR
and might fail with anE
. -
type
ZTest[-R, +E] = ZIO[R, TestFailure[E], TestSuccess]
A
ZTest[R, E]
is an effectfully produced test that requires anR
and may fail with anE
. -
type
ZTestEnv = TestClock with TestConsole with TestRandom with TestSystem
A
ZRTestEnv
is an alias for all ZIO provided Restorable TestEnvironment objects
Value Members
-
def
assert[A](value: ⇒ A)(assertion: Assertion[A]): TestResult
Checks the assertion holds for the given value.
-
val
assertCompletes: TestResult
Asserts that the given test was completed.
-
def
assertM[R, E, A](effect: ZIO[R, E, A])(assertion: AssertionM[A]): ZIO[R, E, TestResult]
Checks the assertion holds for the given effectfully-computed value.
-
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]
A version of
check
that accepts six random variables. -
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]
A version of
check
that accepts five random variables. -
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
check
that accepts four random variables. -
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
check
that accepts three random variables. -
def
check[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) ⇒ TestResult): ZIO[R, Nothing, TestResult]
A version of
check
that accepts two random variables. -
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.
-
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]
A version of
checkAll
that accepts six random variables. -
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]
A version of
checkAll
that accepts five random variables. -
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
checkAll
that accepts four random variables. -
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
checkAll
that accepts three random variables. -
def
checkAll[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) ⇒ TestResult): ZIO[R, Nothing, TestResult]
A version of
checkAll
that accepts two random variables. -
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
Gen
that comprehensively explore all possibilities in a given domain. -
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]
A version of
checkAllM
that accepts six random variables. -
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]
A version of
checkAllM
that accepts five random variables. -
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]
A version of
checkAllM
that accepts four random variables. -
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]
A version of
checkAllM
that accepts three random variables. -
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]
A version of
checkAllM
that accepts two random variables. -
def
checkAllM[R, R1 <: R, E, A](rv: Gen[R, A])(test: (A) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, 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
Gen
that comprehensively explore all possibilities in a given domain. -
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]
A version of
checkM
that accepts six random variables. -
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]
A version of
checkM
that accepts five random variables. -
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]
A version of
checkM
that accepts four random variables. -
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]
A version of
checkM
that accepts three random variables. -
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]
A version of
checkM
that accepts two random variables. -
def
checkM[R, R1 <: R, E, A](rv: Gen[R, A])(test: (A) ⇒ ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]
Checks the effectual test passes for "sufficient" numbers of samples from the given random variable.
-
def
checkN(n: Int): CheckN
Checks the test passes for the specified number of samples from the given random variable.
-
def
checkNM(n: Int): CheckNM
Checks the effectual test passes for the specified number of samples from the given random variable.
-
val
defaultTestRunner: TestRunner[test.environment.TestEnvironment, Any]
A
Runner
that provides a default testable environment. -
def
failed[E](cause: Cause[E]): ZIO[Any, TestFailure[E], Nothing]
Creates a failed test result with the specified runtime cause.
-
val
ignored: ZIO[Any, Nothing, TestSuccess]
Creates an ignored test result.
-
def
platformSpecific[R, E, A](js: ⇒ A, jvm: ⇒ A)(f: (A) ⇒ ZTest[R, E]): ZTest[R, E]
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.
-
def
suite[R, E, T](label: String)(specs: Spec[R, E, T]*): Spec[R, E, T]
Builds a suite containing a number of other specs.
-
def
test(label: String)(assertion: ⇒ TestResult): ZSpec[Any, Nothing]
Builds a spec with a single pure test.
-
def
testM[R, E](label: String)(assertion: ⇒ ZIO[R, E, TestResult]): ZSpec[R, E]
Builds a spec with a single effectful test.
-
final macro
def
typeCheck(code: String): UIO[Either[String, Unit]]
Returns either
Right
if the specified string type checks as valid Scala code orLeft
with an error message otherwise.Returns either
Right
if the specified string type checks as valid Scala code orLeft
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
-
def
versionSpecific[R, E, A](dotty: ⇒ A, scala2: ⇒ A)(f: (A) ⇒ ZTest[R, E]): ZTest[R, E]
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.
-
object
Annotations
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 ofAnnotations
as a more structured logging service or as a super polymorphic version of the writer monad effect. - object Assertion extends AssertionVariants
- object AssertionData
- object AssertionM
- object AssertionMData
- object AssertionValue
- object BoolAlgebra extends Serializable
- object BoolAlgebraM extends Serializable
- object CheckVariants
- object DefaultTestReporter
- object Eql
- object FailureRenderer
- object Gen extends GenZIO with FunctionVariants with TimeVariants with Serializable
- object GenFailureDetails
- object RenderedResult extends Serializable
- object Sample extends Serializable
- object Sized
- object Spec extends Serializable
- object SummaryBuilder
- object TestAnnotation extends Serializable
- object TestAnnotationMap
- object TestAnnotationRenderer
- object TestArgs extends Serializable
- object TestAspect extends TimeoutVariants
- object TestExecutor
- object TestFailure
- object TestLogger
-
object
TestPlatform
TestPlatform
provides information about the platform tests are being run on to enable platform specific test configuration. - object TestReporter
- object TestSuccess
-
object
TestVersion
TestVersion
provides information about the Scala version tests are being run on to enable platform specific test configuration. - object ZTest