前言
单元测试是软件开发过程中非常重要的一环,只有“基础”牢固了,系统这座“大厦”才能稳定运行(抄自知乎)。
一、cmocka是什么?
cmocka is an elegant unit testing framework for C with support for mock objects. It only requires the standard C library, works on a range of computing platforms (including embedded) and with different compilers.
Features:
Tests written with cmocka are compiled into stand-alone executables and linked with the CMock library, the standard C library and module being tested. Any symbols external to the module being tested should be mocked - replaced with functions that return values determined by the test - within the test application. Even though significant differences may exist between the target execution environment of a code module and the environment used to test the code the unit testing is still valid since its goal is to test the logic of a code modules at a functional level and not necessarily all of its interactions with the target execution environment.
The CMocka library provides:
- Support for mock objects.
- Test fixtures.
- Only requires a C library
- Exception handling for signals (SIGSEGV, SIGILL, ...)
- No use of fork()
- Very well tested
- Testing of memory leaks, buffer overflows and underflows.
- A set of assert macros.
- Several supported output formats (stdout, TAP, JUnit XML, Subunit)
- License: Apache License 2.0
二、使用步骤
cmocka官网
cmocka使用说明
cmocka API说明
总结
版权归原作者 qq_39789292 所有, 如有侵权,请联系我们删除。