Skip to main content
Version: 2.x

Flaky and Non-flaky Tests

Whenever we deal with concurrency issues or race conditions, we should ensure that our tests pass consistently. The nonFlaky is a test aspect to do that.

It will run a test several times, by default 100 times, and if all those times pass, it will pass, otherwise, it will fail:

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

test("random value is always greater than zero") {
for {
random <- Random.nextIntBounded(100)
} yield assertTrue(random > 0)
} @@ nonFlaky

Additionally, there is a TestAspect.flaky test aspect which retries a test until it succeeds.

ZIO Chat

Hi there! 👋 I'm ZIO Chat, your friendly neighborhood ZIO expert. I'm here to help you navigate the world of ZIO. Whether you're a seasoned pro or just starting out, fire away with your ZIO questions. I will hit you back with the best insights I've got. Let's dive into the world of ZIO together!