views:

42

answers:

1

I am trying to auto-generate Unit Tests for my C code using API sanity autotest.

But, the problem is that it is somewhat complex to use, and some tutorials / howto / other resources on how to use it would be really helpful.

Have you had any luck with API sanity autotest? Do you think there's a better tool that can be used to auto-generate unit tests for C code?

+1  A: 

It's a recipe for disaster in the first place. If you auto-generate unit tests, you're going to get a bunch of tests that don't mean a lot. If you have a library that is not covered in automated tests then, by definition, that library is legacy code. Consider following the conventional wisdom for legacy code...

For each change:

  1. Pin behavior with tests
  2. Refactor to the open-closed principle (harder to do with C but not impossible)
  3. Drive changes for new code with tests

Also consider picking up a copy of Working Effectively with Legacy Code.

EDIT:

As a result of our discussion, it has become clear that you only want to enforce some basic standards, such has how null pointer values are handled, with your generated tests. I would argue that you don't need generated tests. Instead you need a tool that inspects a library and exercises its functions dynamically, ensuring that it meets some coding standards you have defined. I'd recommend that you write this tool, yourself, so that it can take advantage of your knowledge of the rules you want enforced and the libraries that are being tested.

Automatic UT generation cannot guess intent, but, I want to save the trouble of writing 'routine' tests by using automatic generation.Of course, useless tests will be removed.I'll take a look at the book you've mentioned, thank you.
rmk
@rmk: What would be an example of a "rountine" test?
A test that just exercises the sanity checking code in the C functions I have written, e.g., NULL pointers are handled properly by functions that take ptrs as input, numerical values of inputs to certain functions are within acceptable limits etc.I think autogeneration should be able to show me these corner cases at least.
rmk