Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ZIO Test: failFast operator #5181

@reibitto

Description

@reibitto

This was something I brought up on the Discord earlier but I thought I'd create an issue because it actually looks like more work than it seemed at first and I don't want it to get lost.

So the basic idea is that I'd like to fail a test early if an assertion failed. This is especially useful for costly integration tests where if step 1 failed, it doesn't make sense to run steps 2-10 and collect all the TestResults until the end of the for comprehension.

Basically something like this:

for {
  result1 <- getFromDB(...)
  _ <- failFast {
    assertTrue(result1 == ...)
  }
  result2 <- getFromDB(...)
  // ... do a bunch of other stuff ...
} yield assertTrue(result2 == ...)

There might be better options for naming/syntax (such as attaching an operator on the assertion result itself), but this is just a temporary helper I made in the meantime:

def failFast(testResult: TestResult): UIO[TestResult] =
  UIO(testResult).filterOrDieMessage(_.isSuccess)("Failed fast")

The difficult part is rendering a helpful assertion error message from this point in the code. The last time I looked, I didn't see an obvious place to hook into the test result renderer from there. Maybe I just missed something. Hopefully supporting this doesn't require too much internal restructuring of the code, but I don't know enough to say.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions