Proposal: Enhancing unittest with Inline Module-Level Statements
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Wed Nov 20 09:48:06 UTC 2024
On Tuesday, November 19, 2024 11:11:58 PM MST Sharif yt via Digitalmars-d
wrote:
> Hello D enthusiasts,
>
> One of D's standout features is its built-in unittest, which
> makes writing and maintaining test cases seamless and integrated.
> However, while working with the current unittest block structure,
> I’ve been experimenting with a more concise module-level
> statement for simpler assertions.
>
> Inspired by an idea I came across (and expanded upon), this
> approach allows inline assertions using unittest() with
> parentheses instead of braces {}. Here’s an example:
>
> d
> Copy code
> unittest(1 == 1);
> unittest(1 == 1, "Math broke");
> What do you think about extending D's unittest capabilities in
> this way? Could it make testing in D even more accessible and
> enjoyable?
Personally, I think that it will just encourage writing poor unit tests.
Properly testing a function requires far more than a line or two unless the
functions is absolutely trivial. And if you're writing more than a line or
two, it just makes more sense to use the unittest blocks that we have. We
should be encouraging more thorough testing, and this would do the exact
opposite of that.
So, IMHO, this would be adding more complication to the language just to try
to make it easier to write inadequate tests, and I don't think think that we
should be doing that.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list