Live data from Hacker News

MinUnit – A minimal unit testing framework for C (2002)

jera.com

21–30 of 56 posts

Re: MinUnit – A minimal unit testing framework for C (2002)

#22
post #9

Why not just 1 line? Of course, the application will halt after one test fails, but some people like it this way. #include Usage: void test_foo() { assert(foo() == 4 /* foo should be 4 */); } Output would be something like Assertion failed at "foo() == 4 /* foo should be 4 */" If you run the application in a debugger like GDB, you can see the frame when the abort trap is called.

I actually implemented a basic unit test framework in C yesterday and started with basic asserts like you point out, however once I got it working I switched to return values not unlike TFA. The obvious problem with assertions in that they kill your test program immediately at the first failure instead of doing additional tests and potentially give a clearer picture of what's broken exactly. They're also not very flexible if you want to customize the error message since they only stringify the assert parameter. "Assertion `ret == 0' failed." is not super helpful. As sibling comments mention there are ways to work around that by using literal strings and && but it doesn't help if you want to wrap around tests using helper functions etc...

I'm also tempted to say that if you need to use GDB to figure out where your tests have failed exactly your framework is not particularly user friendly. Normally when a test fails it should be pretty clear where it failed and why. The root cause of the issue might be further away of course but then again assertions won't help with that either.

Re: MinUnit – A minimal unit testing framework for C (2002)

#24
post #10
post #7

Earlier quoted context omitted.

Really? Is it perhaps because of those libraries that do their best to make test call sites look like weird pseudo-English. Stuff like having a library function named it(): it(“should be confusing”, function() { ... })

It always really bothered me that there had to be so much syntactical sugar on top of testing frameworks. Unit testing should be written in exactly the syntax of the language you are working with. I don't want to have to carry that additional crap in my working memory while writing code. I can't stand having to look up Gherkin syntax just to write a few dumb tests. The only reason I see the usefulness of additional s…

OTOH never rule out how KISS is the enemy of billable hours and don't underestimate CDD's ability (consultability driven development) to come up with solutions to non problems.

YMMV, the BDD implementations I've seen so far did not convince me of its value to put it mildly.

Re: MinUnit – A minimal unit testing framework for C (2002)

#25

I have a library [link redacted] that was originally designed to extend MinUnit. I love the idea of an all-in-one unit testing library without complicated set up.

Well, there's a fine welcome from HN: new account that's fifteen minutes old, which posts what could be useful information (I just skimmed it) in a non-controversial manner and...insta-dead.

I obviously vouched for the comment, but yeesh.

Re: MinUnit – A minimal unit testing framework for C (2002)

#26
post #2

So, the revelation is that a unit test is an if statement, and if you wrap that into a macro you can call it a framework.

Except that’s not a whole test any more than the punchline is the joke.

It’s sample data, verification, analysis, and reporting. The if statement is just the verification step.

Re: MinUnit – A minimal unit testing framework for C (2002)

#27

Whats up with the do/while loops? Does that just make the return syntactically valid? Apologies, its been a while since I've touched C/C++

GCC has an extension that can be used instead of the do-while loop, see example macro definition here: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

Re: MinUnit – A minimal unit testing framework for C (2002)

#28
For everybody who demands from their test framework that it prints expected vs actual values and file/line references, and that it can be adapted to embedded and bare metal targets I recommend the excellent Unity framework[1], example[2].

--

[0] http://www.throwtheswitch.org/unity/

[1] https://gitlab.com/oliver117/blut/blob/master/test/test_math...

Post reply on HN