4 ms·
Unit tests? In C? I worked on a system processing millions of dollars a day in real time transactions, written in C++ with lower level libraries written in C. S
by icedchai 11y ago
Unit tests? In C? I worked on a system processing millions of dollars a day in real time transactions, written in C++ with lower level libraries written in C. Some of it was written in K&R pre-ANSI C.
There was not one unit test. And there probably still isn't.
- 2trill2spill 11y ago> Unit tests? In C? Why wouldn't you unit test in C? I do and I have found lot's of bugs as a result and maintaining code is much easier.
- icedchai 11y agoI agree. But it seems to happen less than in other languages. I'd say it's not part of the culture.
- deleted 11y ago[deleted]
- icedchai 11y agoIt is, of course, possible. It is just rarely practiced, I think. It is as necessary as it is in any other language, which means either not at all, absolutely necessary, or somewhere in between depending on your point of view... I have seen a few approaches: google test (actually a C++ framework) used to test C code, "custom" test frameworks (makefiles, test-runner shell scripts, and small main() functions that actually run tests), etc.
- redahs 11y agoC is one of the easier languages to do unit testing in: 1. write a new one file script which parses function declarations from a source code file 2. have the script find all function declarations which start with "utest_", accept no parameters, and return "int" or "bool". 3. have the script write out a new C file which calls all of matching unit test functions and asserts their return value is equal to 1 4. have your Makefile build and run a unit test binary using code generated by your script for each source code file containing greater than 0 unit tests. Writing a script to parse function declarations from your C source code is useful because you can extend the script later on to generate documentation, code statistics, or conduct project-specific static analysis.
- brown9-2 11y agoI don't think this is the boast that you think it is.
- icedchai 11y agoIt wasn't meant to be a boast.