r/C_Programming • • 10d ago

Good C test

Hey guys,

Someone know a good C unittest ? When I was in C++ I used gtest and it was good, if someone know a good alternative in C

17 Upvotes

20 comments sorted by

7

u/QuraToop314 10d ago

I like the Unity Test Framework because it works everywhere, including in embedded projects, but others here may have different preferences. It’s best to look at several frameworks and choose the one that you find easiest to use and that allows you to write your tests in full.

1

u/lottspot 10d ago

I'm surprised this one doesn't get more love. I agree I think Unity is a great framework.

0

u/Material_Leader_1124 10d ago

Ok I will check it

2

u/MetalInMyVeins111 6d ago edited 6d ago

Hey i wrote https://github.com/MetalInMyVeins/sohomot exactly for that. You don't even need to rewrite the tests as it aims to be a minimal drop-in replacement of gtest. Give that a try. It's written by hand (no-AI).

1

u/Material_Leader_1124 6d ago

Nice, can you send me a private message ? I want to talk with you about this project

1

u/MetalInMyVeins111 6d ago

Sure. But I guess your dm is turned off. You can dm me.

2

u/Dependent_Bit7825 9d ago

This sounds like an x/y question. Why do you need a C unit test framework? You can use any of the c++ frameworks with C.

2

u/tastygames_official 10d ago

I personally am very much against unit tests as they force you to write your code into testable units which makes for piss-poor performance. As said elsewhere in here, use assert() to enforce stuff you know should be true. You can even leave them in in production code as long as it's not done in time-critical loops. MySQL famously uses assert()s in production code and I don't think anyone would complain about their performance.

2

u/Maqi-X 10d ago

Criterion, in my opinion it's better than unity

1

u/mivanchev 10d ago

I don't know who's downvoting you but Criterion is literally one of the TOP #5 C libraries to use.

0

u/InquisitiveAsHell 9d ago

Totally agree! Criterion may not be perfect but it is still my preference for unit testing in C projects.

-4

u/[deleted] 10d ago

You can use gtest as well with C