4 ms·
When I first leant about unit tests / TDD, I was confused because everyone assumes you are doing OOP. What am I supposed to do with my C code? I can just test a
by sebtron 3y ago
When I first leant about unit tests / TDD, I was confused because everyone assumes you are doing OOP. What am I supposed to do with my C code? I can just test a function, right? Or do I have to forcefully turn my program into some OO-syle architecture?
But then I realized it does not matter, there is only important thing about unit tests: that they exists. All the rest is implementation detail.
Mocking or not, isolated "unit" or full workflow, it does not matter. All I care about is that I can press a button (or type "make test" or whatever) and my tests run and I know if I broke something.
Sure, your tests need to be maintainable, you should not need to rewrite them when you make internal changes, and so on. You'll learn as you go. Just write them and make them easy to run.
- okl 3y agoFor C code you can use link-time substitution and a mock generator like CMock (http://www.throwtheswitch.org/cmock http://www.throwtheswitch.org/cmock). Link-time substitution means that you swap out certain objects with others when you build your test binaries. For example, let's say your production software binary consists of a main function and objects A, B and C. For a unit test you could use a different main (the test), object B and a mock for object C - leaving out A.