2 ms·
Would you mind giving an example of how you would unit test a function?
by pagnol 9y ago
Would you mind giving an example of how you would unit test a function?
- int_19h 9y agoThe 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 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 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.