Skip to main content
Version: 2.x

Passing Failed Tests

The failing aspect makes a test that failed for any reason pass.

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

test("passing a failing test") {
assertTrue(false)
} @@ TestAspect.failing

If the test passes this aspect will make it fail:

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

test("failing a passing test") {
assertTrue(true)
} @@ TestAspect.failing

It is also possible to pass a failing test on a specified failure:

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

test("a test that will only pass on a specified failure") {
ZIO.fail("Boom!").map(_ => assertTrue(true))
} @@ TestAspect.failing[String] {
case TestFailure.Assertion(_, _) => true
case TestFailure.Runtime(cause: Cause[String], _) => cause match {
case Cause.Fail(value, _)
if value == "Boom!" => true
case _ => false
}
}

ZIO Chat

๐ŸŒŸ Greetings from ZIO Chat! ๐ŸŒŸ Have questions about ZIO? Look no further! I'm here to be your ZIO guru. Whether you're a seasoned pro or just starting out, I've got answers tailored just for you. Fire away with your ZIO queries, and I'll hit you back with the best insights I've got. Let's dive into the world of ZIO together!