Skip to main content
Version: 2.0.x

Before, After, and Around Test Aspects

  1. We can run an effect before, after, or around every test:
  • TestAspect.before
  • TestAspect.after
  • TestAspect.afterFailure
  • TestAspect.afterSuccess
  • TestAspect.around
import zio._
import zio.test.{ test, _ }

test("before and after") {
for {
tmp <- System.env("TEMP_DIR")
} yield assertTrue(tmp.contains("/tmp/test"))
} @@ TestAspect.before(
TestSystem.putEnv("TEMP_DIR", s"/tmp/test")
) @@ TestAspect.after(
  1. The TestAspect.aroundTest takes a scoped resource and evaluates every test within the context of the scoped function.

  2. There are also TestAspect.beforeAll, TestAspect.afterAll, afterAllFailure, afterAllSuccess, and TestAspect.aroundAll variants.

  3. Using TestAspect.aroundWith and TestAspect.aroundAllWith we can evaluate every test or all test between two given effects, before and after, where the result of the before effect can be used in the after effect.