News for hackers. Stuff that matters.
Re:MinUnit: a minimal unit testing framework for C by pagnol on Tuesday May 09, 2017 @04:38AM (#14298533)
Would you mind giving an example of how you would unit test a function?
Re:MinUnit: a minimal unit testing framework for C by int_19h on Tuesday May 09, 2017 @05:09PM (#14303838)
The same way you would unit test a Python function, except you invoke the actual C function using e.g. ctypes:

https://docs.python.org/3/library/ctypes.html

but your unit test is written in Python, including all the setup/teardown stuff and asserts. And you run it using the stock Python test runner (or some wrapper around that):

https://docs.python.org/3/library/unittest.html

(In theory, this all can be done even smoother if you use Cython, because that lets you interface with C more naturally than ctypes. I haven't tried that, though.)

Note that this all makes sense for C APIs, not C++ ones. With C++ APIs, as soon as classes etc come into the picture, and especially once you start dealing with STL and Boost data types, it becomes too difficult to invoke that stuff from Python. However, the implementation can be in any language - what matters is what the tested API looks like.