gomega icon indicating copy to clipboard operation
gomega copied to clipboard

Implement soft assertions

Open coding-yogi opened this issue 4 years ago • 1 comments

Currently the test fails at first assertion and will not proceed further, Most of the times this does the job. Sometimes you still want to proceed and check for rest of the assertions, ultimately failing the test if any of the soft assertions have failed , and then report all the failed assertions

coding-yogi avatar Feb 08 '21 07:02 coding-yogi

Most of the situations where I've seen this requirement it's because people want more data when the test fails, for example:

code, message := foo()
Expect(code).To(BeZero()) // <- Fails here
Expect(message).To(BeEmpty()) // <- Never see what this was

But when it fails, it's really useful to know what message is. In this case you can do:

code, message := foo()
Expect(code).To(BeZero(), fmt.Sprintf("message: %s\n", message))
Expect(message).To(BeEmpty())

I think implementing "soft" assertions could be quite difficult and controversial, so I'd like to dig a bit deeper into the use case because it might be that the behavior you want is achievable already.

blgm avatar Feb 12 '21 23:02 blgm