如何向已建立的 (autotools) C 项目添加单元测试
我有一个带有一些新功能的 openssh 分支,并且想要编写一些单元测试以确保它们在构建时工作。嫁接检查openssh的autotools配置很困难(因为我不太了解autotools)
有没有更容易使用的C单元测试框架?一种与自动工具关系不太密切的工具? 是否有更好的方法将 Check 添加到该项目而不从根本上更改其构建文件?
I have a fork of openssh with some new features and want to write some unit tests to make sure they work at build. Grafting Check into openssh's autotools configuration is diffacult (because I don't really understand autotools)
Is there an easier to use C unit test framework? One less closely tied to autotools?
How about a better way of going about adding Check to this project with out radically changing its build files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果目标是将这些新功能集成到主分支中,那么放弃自动工具可能不是一个好主意。这个SO问题指向一些可能有用的自动工具教程。
另外,还有几个可用于 C 的单元框架:最臭名昭著的是 Cunit、Check、minunit、CMockery,请参阅 这个问题 或此列表。
It might not be a good idea to move away from autotools if the objective is to integrate those new features in the main branch. This SO question is pointing to several tutorials for autotools that could be helpful.
Otherwise, there are several unit framework available for C: the most notorious are Cunit, Check, minunit, CMockery, refer to this question or this list.
通过创建单独的构建,可以最轻松地完成互连代码的单元测试。这允许使用 Mock 对象在链接时替换其他编译单元,并免费使用 C 预处理器:
Grenning 有一本关于嵌入式 C 测试驱动开发的好书。
Unit testing of interlinked code is most easily accomplished by creating separate builds. This allows e.g. link-time replacement of other compilation units with Mock objects, and free use of the C preprocessor:
There's a good book on Test Driven Development for Embedded C by Grenning.