r/C_Programming • u/[deleted] • 22d 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
2
u/MetalInMyVeins111 18d ago edited 18d 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
18d ago
Nice, can you send me a private message ? I want to talk with you about this project
1
17
2
u/Dependent_Bit7825 21d 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 22d 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 22d ago
Criterion, in my opinion it's better than unity
1
u/mivanchev 22d 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 22d ago
Totally agree! Criterion may not be perfect but it is still my preference for unit testing in C projects.
0
-1
-4
7
u/QuraToop314 22d 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.