-
Couldn't load subscription status.
- Fork 1.4k
Description
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.