Python based Unit test Frameworks like "nose" have a lot of rich features, i wonder if we can leverage them to test C Code.
Of course you can.... but you'll have to write a binding to call your C code in python (with ctypes for example), and write the tests in python (this is really possible and an easy way to do smart tests)
Example :
foolib.c
int my_sum(int , int);
int my_sum(int a , int b);
{
return a + b;
}
gcc -shared -Wl,-soname,foolib -o foolib.so -fPIC foolib.c
foolib_test.py
import ctypes
import unittest
class FooLibTestCase(unittest.TestCase):
def setUp(self):
self.foolib = ctypes.CDLL('/full/path/to/foolib.so')
def test_01a(self):
""" Test in an easy way"""
self.failUnlessEqual(4, foolib.my_sum(2, 2))
And then, when running this test with nose you should have a nice test of your C code :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With