Soft Assertions? Rarely Useful

I remember some time ago I was really excited about the idea of soft assertions. The latest blog post by Rafał Borowiec reminded me about them. …but wait, if I was so crazy about them some time ago, then how it happened that now I need to be reminded about their existence?

So first of all, I believe they make sense only for integration or e2e tests. Only, where execution of test is so costly (in terms of time) that you really, really want to learn as much about the tested scenario as possible. So, if you have a long (Webdriver) test, which ends with bunch of asserts, then I think it might make sense to write them using soft assertions.

But for unit tests? Oh no, you do not need soft asserts! Execution of such test takes milliseconds so rerunning them is simply a matter of few keystrokes using your IDE. Not much gained by soft asserts here.
And I also see a potential downside. I think that using soft asserts might lead you into the wrong direction: it might encourage you to verify much more then required, or to verify different thing “because you can”. No, thank you, I strongly believe you should go with one (logical!) assertion per test.

So, all in all, my initial excitement about the soft assertions has vanished over the years. I would never use them for unit tests, and I do not use them for other kind of tests. Why not? I think that when I first learned about them they were not supported by the tools so I gave up the idea. And later… well, I think I got used to not using them, and as I think now about my E2E/GUI/Integration tests I do not see compelling reasons to change my mind.

Just my 3 cents.

Leave a Reply

Your email address will not be published. Required fields are marked *