Unit Testing Libraries for C

The last time I did some unit testing on C, I used Novaprova . However, at least at the moment, this doesn’t run on non-Intel platforms (like the ARM based Pi).

I decided to make a quick survey of what tools there are. I focused mainly on the ones that are already available through Linux package managers.

Everyone loves Autotools

The leading approach seems to be to use autotools’ built-in test runner i.e. “make check”.

To choose two of my favourite projects at random, VLC and JSON-C, both follow this approach.

Using GCC’s built-in preprocessor and linker gets you some way to mocking and so on.

A lot of applications roll their own test runners using bash or Python scripts.

If you are using a big framework, you may have already installed testing utilities as part of it, for example GNOME’s Glib and Boost (which is C++) both come with their own testing tools.

Without further ado, onward to the tables. Currently, these are just in approximate alphabetical order.

C Only

NameApt PackageProjects Using It
CheckcheckExpat, GStreamer
cmockacmockalibssh, OpenVPN
GNU Autounitlibautounit-dev

C and C++

NameApt PackageProjects Using It
API Sanity Checkerapi-sanity-checker
Criterioncriterion-dev (ppa)
CTest (CMake)cmakeNetflix, ZeroMQ, libpng, Poppler
Cuttercutter-testing-frameworklibnfc, Groonga
DejaGnudejagnuGCC, Other GNU tools
Google TestgoogletestChromium, LLVM, OpenCV, Blender

C++ Only

There are loads of C++ testing utilities such as Catch and CxxTest (and too many others to mention) that do not claim explicit support for C.

If you want to use one of those, you can just test your C code using a C++ compiler.

Some purists will object, as in this Stackoverflow comment :

I know C and C++ has a lot of overlap, but it doesn’t strike me as a good idea to use a C++ testing library when you’re producing code that will be ultimately compiled in a C compiler

Tell me your stories

I haven’t had the opportunity yet to go beyond listing them.

What are you using? What have I missed?

I’m especially keen to get more information to fill in the third column in the table above (i.e. what any testing tools vaguely well known open source projects use).

稿源:Zeth.net (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合技术 » Unit Testing Libraries for C

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录