logoalt Hacker News

crabbonetoday at 8:53 AM1 replyview on HN

There's a whole big contentious point that the author completely ignored: using assertions in tests (like unit-tests). Some unit testing frameworks expect their users to use assertions to do the job, others are very much against it because they want to separate between the failures of the system under test from failures of the test. (If that matters, I'm in the later camp).

* * *

I also think that the article confuses the how assert works at present (in some languages. Obviously, not Prolog, for example :D), and how he wants it to work. Sometimes his reasoning for doing one thing or the other is based on how assert works today, and sometimes it's based on how he wishes for it to work. Both have merit, but put together don't make much sense.

As for me, I think that the bullet points the author gives for the "proper" use of assertions need to be covered by different tools. Especially if the program is to be compiled with optimizations. I don't think there can be a general rule to tell if an assertion should stay at runtime or not. Sometimes it will depend on the knowledge about the environment in which the program will run. So, you'd need "persistent assertions" and "transient assertions" for the lack of a better word, where "persistent assertion" is functionally an exception, it just checks the same thing as the "transient assertion" would, so it makes sense that they are both called "assertions".


Replies

lelanthrantoday at 9:50 AM

> Some unit testing frameworks expect their users to use assertions to do the job, others are very much against it because they want to separate between the failures of the system under test from failures of the test. (If that matters, I'm in the later camp).

How useful is this distinction in practice? A failing test is going to examined in detail and that examination is going to reveal whether the system under test failed or if the test itself failed.

I guess I am asking, when is this distinction useful?

show 1 reply