使用cmocka实现嵌入式单元测试

本文介绍了cmocka,一个轻量级且跨平台的C语言单元测试框架,支持mock对象和多种输出格式。重点讲述了其基本概念、特点以及使用资源链接。
摘要由CSDN通过智能技术生成

前言

单元测试是软件开发过程中非常重要的一环,只有“基础”牢固了,系统这座“大厦”才能稳定运行(抄自知乎)。

一、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说明


总结

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值