N
nroberts
Something I've been trying to do and my bosses have wanted me to
continue is to apply unit testing to the code I'm working with. In
some cases this has been fairly straight forward but in others it has
not. Some of what I've tried to do to harness some of the code has
been discouraged and I'm not so sure much of what I'd do in C++ or
Java lends itself directly to C.
For example, unit testing often requires strong use of polymorphism,
abstract types, inheritance, dependency injection, mocks, etc... You
CAN do these things in C but if you were to that extent then you're
almost wasting your time and effort reimplementing C++ or Objective-C
(depending on the static/dynamic approach you want) for no good
reason. You do perhaps have a modicum of more control but beating
those languages at what they do by hand is a pretty lofty goal.
Perhaps unit testing isn't often done in C either, as might be
indicated by how different I used the term from everyone else in the
new job, but certainly there must be others that do it as it is a well
known way to measurably increase the dependency and maintainability of
your code. What then are some good C techniques to make code unit
testable that hopefully fit in nicer with the C paradigm than going
all OO or generic?
continue is to apply unit testing to the code I'm working with. In
some cases this has been fairly straight forward but in others it has
not. Some of what I've tried to do to harness some of the code has
been discouraged and I'm not so sure much of what I'd do in C++ or
Java lends itself directly to C.
For example, unit testing often requires strong use of polymorphism,
abstract types, inheritance, dependency injection, mocks, etc... You
CAN do these things in C but if you were to that extent then you're
almost wasting your time and effort reimplementing C++ or Objective-C
(depending on the static/dynamic approach you want) for no good
reason. You do perhaps have a modicum of more control but beating
those languages at what they do by hand is a pretty lofty goal.
Perhaps unit testing isn't often done in C either, as might be
indicated by how different I used the term from everyone else in the
new job, but certainly there must be others that do it as it is a well
known way to measurably increase the dependency and maintainability of
your code. What then are some good C techniques to make code unit
testable that hopefully fit in nicer with the C paradigm than going
all OO or generic?