Skip to main content
Version: 2.x

Configuring Tests

To run cases, there are some default configuration settings which are used by test runner, such as repeats, retries, samples and shrinks. We can change these settings using test aspects:

Number of Repeatsโ€‹

The repeats(n: Int) test aspect runs each test with the number of times to repeat tests to ensure they are stable set to the specified value:

import zio._
import zio.test.{ test, _ }

test("repeating a test") {
ZIO.attempt("Repeating a test to ensure its stability")
.debug
.map(_ => assertTrue(true))
} @@ TestAspect.nonFlaky @@ TestAspect.repeats(5)

Number of Retriesโ€‹

The retries(n: Int) test aspect runs each test with the number of times to retry flaky tests set to the specified value.

Number of Samplesโ€‹

The samples(n: Int) test aspect runs each test with the number of sufficient samples to check for a random variable set to the specified value.

Let's change the number of default samples in the following example:

import zio._
import zio.test.{ test, _ }

test("customized number of samples") {
for {
ref <- Ref.make(0)
_ <- check(Gen.int)(_ => assertZIO(ref.update(_ + 1))(Assertion.anything))
value <- ref.get
} yield assertTrue(value == 50)
} @@ TestAspect.samples(50)

Maximum Number of Shrinksโ€‹

The shrinks(n: Int) test aspect runs each test with the maximum number of shrinkings to minimize large failures set to the specified value.

ZIO Chat

Hello! ๐Ÿ˜Š I'm your ZIO Chat Bot, designed to be your go-to resource for all things ZIO! Whether you're new to this powerful functional effect system or a seasoned pro, I'm here to assist you. ZIO empowers you to build concurrent and resilient applications in Scala, offering referential transparency, composable data types, type-safety, and more. So, go ahead and ask me anything about ZIO โ€“ I'm here to provide the answers you need! ๐Ÿค–