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)) } } }
- Alphabetic
- By Inheritance
- test
- CompileVariants
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
abstract
class
AbstractRunnableSpec extends AnyRef
- Annotations
- @EnableReflectiveInstantiation()
- type AssertResult = BoolAlgebra[AssertionValue]
-
class
Assertion[-A] extends (⇒ A) ⇒ AssertResult
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 conjuction and disjunction, and can be negated. -
sealed
trait
AssertionValue extends AnyRef
An
AssertionValuekeeps track of a assertion and a value, existentially hiding the type.An
AssertionValuekeeps 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. -
sealed
trait
BoolAlgebra[+A] extends Product with Serializable
A
BoolAlgebra[A]is a description of logical operations on values of typeA. - trait CompileVariants extends AnyRef
-
abstract
class
DefaultRunnableSpec extends RunnableSpec[TestEnvironment, String, Any, Any, Any]
A default runnable spec that provides testable versions of all of the modules in ZIO (Clock, Random, etc).
-
type
ExecutedSpec[+L, +E, +S] = Spec[Any, Nothing, L, Either[TestFailure[E], TestSuccess[S]]]
An
ExecutedSpecis a spec that has been run to produce test results. - sealed trait ExecutionStrategy extends AnyRef
-
final
case class
FailureDetails(assertion: ::[AssertionValue], gen: Option[GenFailureDetails] = None) extends Product with Serializable
FailureDetailskeeps track of details relevant to failures. - trait FunctionVariants extends AnyRef
-
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
GenFailureDetailskeeps track of relevant information related to a failure in a generative test. - trait GenZIO extends AnyRef
- case class RenderedResult(caseType: CaseType, label: String, status: Status, offset: Int, rendered: Seq[String]) extends Product with Serializable
-
abstract
class
RunnableSpec[R, L, T, E, S] extends AbstractRunnableSpec
A
RunnableSpechas 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.
- trait Sized extends AnyRef
-
final
case class
Spec[-R, +E, +L, +T](caseValue: SpecCase[R, E, L, T, Spec[R, E, L, T]]) extends Product with Serializable
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 typeT. All specs are annotated with labels of typeL, require an environment of typeRand may potentially fail with an error of typeE. -
final
class
TestAnnotation[V] extends AnyRef
A type of annotation.
-
class
TestAnnotationMap extends AnyRef
An annotation map keeps track of annotations of different types.
- case class TestArgs(testSearchTerms: List[String]) extends Product with Serializable
-
trait
TestAspect[+LowerR, -UpperR, +LowerE, -UpperE, +LowerS, -UpperS] extends AnyRef
A
TestAspectis an aspect that can be weaved into specs.A
TestAspectis 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. -
type
TestAspectPoly = TestAspect[Nothing, Any, Nothing, Any, Nothing, Any]
A
TestAspectPolyis aTestAspectthat is completely polymorphic, having no requirements on error or environment. -
type
TestExecutor[+R, L, -T, E, +S] = (ZSpec[R, E, L, T], ExecutionStrategy) ⇒ UIO[ExecutedSpec[L, E, S]]
A
TestExecutor[R, L, T, E, S]is capable of executing specs containing tests of typeT, annotated with labels of typeL, that require an environmentRand may fail with anEor succeed with aS. - sealed trait TestFailure[+E] extends AnyRef
- trait TestLogger extends AnyRef
-
type
TestReporter[-L, -E, -S] = (Duration, ExecutedSpec[L, E, S]) ⇒ URIO[TestLogger, Unit]
A
TestReporter[L, E, S]is capable of reporting test results annotated with labelsL, error typeE, and success typeS. - type TestResult = BoolAlgebra[FailureDetails]
-
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
A
TestRunner[R, E, L, S]encapsulates all the logic necessary to run specs that require an environmentRand may fail with an errorEor succeed with anS, using labels of typeL.A
TestRunner[R, E, L, S]encapsulates all the logic necessary to run specs that require an environmentRand may fail with an errorEor succeed with anS, using labels of typeL. Test runners require a test executor, a platform, and a reporter. - sealed trait TestSuccess[+S] 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, +L, +S] = Spec[R, TestFailure[E], L, TestSuccess[S]]
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 anR, might fail with anE, might succeed with anS, and whose nodes are annotated with labelsL. -
type
ZTest[-R, +E, +S] = ZIO[R, TestFailure[E], TestSuccess[S]]
A
ZTest[R, E, S]is an effectfully produced test that requires anRand may fail with anEor succeed with aS.
Value Members
-
final
def
assert[A](value: ⇒ A, assertion: Assertion[A]): TestResult
Checks the assertion holds for the given value.
-
final
val
assertCompletes: TestResult
Asserts that the given test was completed.
-
final
def
assertM[R, E, A](value: ZIO[R, E, A], assertion: Assertion[A]): ZIO[R, E, TestResult]
Checks the assertion holds for the given effectfully-computed value.
-
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]
A version of
checkthat accepts four random variables. -
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]
A version of
checkthat accepts three random variables. -
final
def
check[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) ⇒ TestResult): ZIO[R, Nothing, TestResult]
A version of
checkthat accepts two random variables. -
final
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.
-
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]
A version of
checkAllthat accepts four random variables. -
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]
A version of
checkAllthat accepts three random variables. -
final
def
checkAll[R, A, B](rv1: Gen[R, A], rv2: Gen[R, B])(test: (A, B) ⇒ TestResult): ZIO[R, Nothing, TestResult]
A version of
checkAllthat accepts two random variables. -
final
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
Genthat comprehensively explore all possibilities in a given domain. -
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]
A version of
checkAllMthat accepts four random variables. -
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]
A version of
checkAllMthat accepts three random variables. -
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]
A version of
checkAllMthat accepts two random variables. -
final
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
Genthat comprehensively explore all possibilities in a given domain. -
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]
A version of
checkMthat accepts four random variables. -
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]
A version of
checkMthat accepts three random variables. -
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]
A version of
checkMthat accepts two random variables. -
final
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.
-
final
def
checkSome(n: Int): CheckSome
Checks the test passes for the specified number of samples from the given random variable.
-
final
def
checkSomeM(n: Int): CheckSomeM
Checks the effectual test passes for the specified number of samples from the given random variable.
-
final
def
failed[E](cause: Cause[E]): ZTest[Any, E, Nothing]
Creates a failed test result with the specified runtime cause.
-
final
val
ignored: ZTest[Any, Nothing, Nothing]
Creates an ignored test result.
-
final
def
platformSpecific[R, E, A, S](js: ⇒ A, jvm: ⇒ A)(f: (A) ⇒ ZTest[R, E, S]): ZTest[R, E, S]
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.
-
final
def
suite[R, E, L, T](label: L)(specs: Spec[R, E, L, T]*): Spec[R, E, L, T]
Builds a suite containing a number of other specs.
-
final
def
test[L](label: L)(assertion: ⇒ TestResult): ZSpec[Any, Nothing, L, Unit]
Builds a spec with a single pure test.
-
final
def
testM[R, E, L](label: L)(assertion: ⇒ ZIO[R, E, TestResult]): ZSpec[R, E, L, Unit]
Builds a spec with a single effectful test.
-
final macro
def
typeCheck(code: String): UIO[Either[String, Unit]]
Returns either
Rightif the specified string type checks as valid Scala code orLeftwith an error message otherwise.Returns either
Rightif the specified string type checks as valid Scala code orLeftwith 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
-
final
def
versionSpecific[R, E, A, S](dotty: ⇒ A, scala2: ⇒ A)(f: (A) ⇒ ZTest[R, E, S]): ZTest[R, E, S]
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 Assertion
- object AssertionValue
- object BoolAlgebra extends Serializable
- object CheckVariants
- object DefaultTestReporter
-
object
DefaultTestRunner extends TestRunner[TestEnvironment, String, Any, Any, Any]
A
Runnerthat provides a default testable environment. - object ExecutionStrategy
- 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
- object TestAnnotationMap
- object TestArgs extends Serializable
- object TestAspect extends TimeoutVariants
- object TestExecutor
- object TestFailure
- object TestLogger
-
object
TestPlatform
TestPlatformprovides information about the platform tests are being run on to enable platform specific test configuration. - object TestReporter
- object TestSuccess
-
object
TestVersion
TestVersionprovides information about the Scala version tests are being run on to enable platform specific test configuration.