单元测试C code [英] Unit Testing C Code

查看:404
本文介绍了单元测试C code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾在嵌入式系统上今年夏天写的直线C.这是现有的项目,该公司为我接管工作。我已经很习惯了使用JUnit用Java编写单元测试,但在亏损,以编写现有code单元测试(这需要重构),以及新的code的最佳方式添加到系统

I worked on an embedded system this summer written in straight C. It was an existing project that the company I work for had taken over. I have become quite accustomed to writing unit tests in Java using JUnit but was at a loss as to the best way to write unit tests for existing code (which needed refactoring) as well as new code added to the system.

有没有在外面,使得单元测试普通的C code容易,因为单元测试Java code使用JUnit的项目?这将专门适用于嵌入式开发任何见解(交叉编译为arm-linux平台)将大大AP preciated。

Are there any projects out there that make unit testing plain C code as easy as unit testing Java code with JUnit? Any insight that would apply specifically to embedded development (cross-compiling to arm-linux platform) would be greatly appreciated.

推荐答案

在C一根单元测试框架是检查; A( 2008 上次更新)用C单元测试框架的名单可以发现这里和转载如下。根据有多少标准库函数运行时有,你可能还是不能够使用其中的一个。

One unit testing framework in C is Check; a (LAST UPDATED ON 2008) list of unit testing frameworks in C can be found here and is reproduced below. Depending on how many standard library functions your runtime has, you may or not be able to use one of those.

AceUnit(高级C和嵌入式设备)自称是一个舒适的çcode单元测试框架。它试图致力于模拟的JUnit 4.x和包括反射般的能力。 AceUnit可以在资源约束的环境中,例如用于嵌入式软件开发,以及重要的是它运行在环境优良,你不能有一个标准的头文件,不能调用从ANSI / ISO C库的单一标准的C函数。它也有一个Windows端口。它不使用叉捕获的信号,尽管作者在加入这样的功能前pressed兴趣。请参阅 AceUnit首页

AceUnit

AceUnit (Advanced C and Embedded Unit) bills itself as a comfortable C code unit test framework. It tries to mimick JUnit 4.x and includes reflection-like capabilities. AceUnit can be used in resource constraint environments, e.g. embedded software development, and importantly it runs fine in environments where you cannot include a single standard header file and cannot invoke a single standard C function from the ANSI / ISO C libraries. It also has a Windows port. It does not use forks to trap signals, although the authors have expressed interest in adding such a feature. See the AceUnit homepage.

沿着相同的路线的检查,包括分叉能够运行在一个独立的地址空间的单元测试很多(实际上,检查的原始作者借用了GNU Autounit的想法)。 GNU Autounit使用GLib的广泛应用,这意味着连接和等需要特殊选项,但是这可能不是一个大问题给你,特别是如果你已经在使用GTK或GLib的。请参阅 GNU Autounit首页

Much along the same lines as Check, including forking to run unit tests in a separate address space (in fact, the original author of Check borrowed the idea from GNU Autounit). GNU Autounit uses GLib extensively, which means that linking and such need special options, but this may not be a big problem to you, especially if you are already using GTK or GLib. See the GNU Autounit homepage.

此外使用GLib的,但不分叉,保护单元测试的地址空间。

Also uses GLib, but does not fork to protect the address space of unit tests.

标准C,与一个Win32 GUI实施计划。目前不叉子或以其他方式保护的单元测试的地址空间。在早期的发展。请参阅库尼特首页

Standard C, with plans for a Win32 GUI implementation. Does not currently fork or otherwise protect the address space of unit tests. In early development. See the CUnit homepage.

只有一个.c和你拖放到你的源代码树的上.h文件中一个简单的框架。请参阅可爱首页

A simple framework with just one .c and one .h file that you drop into your source tree. See the CuTest homepage.

有关C ++的premier单元测试框架;你也可以用它来测试C $ C $℃。它是稳定的,积极地开发,并且具有图形用户界面。主要的原因不使用的CppUnit对于C是第一,这是相当大的,其次你必须写在C ++中,这意味着你需要一个C ++编译器你的测试。如果这些听起来不像顾虑,这是绝对值得考虑,与其他C ++单元测试框架一起。请参阅 CppUnit的首页

The premier unit testing framework for C++; you can also use it to test C code. It is stable, actively developed, and has a GUI interface. The primary reasons not to use CppUnit for C are first that it is quite big, and second you have to write your tests in C++, which means you need a C++ compiler. If these don’t sound like concerns, it is definitely worth considering, along with other C++ unit testing frameworks. See the CppUnit homepage.

embUnit(嵌入式设备)是嵌入式系统的另一个单元测试框架。这一次似乎是由AceUnit所取代。 嵌入式设备首页

embUnit (Embedded Unit) is another unit test framework for embedded systems. This one appears to be superseded by AceUnit. Embedded Unit homepage.

一个最小的一套宏,这就是它!关键是要显示它是单位多么容易测试code。请参阅 MinUnit首页

A minimal set of macros and that’s it! The point is to show how easy it is to unit test your code. See the MinUnit homepage.

一个CUNIT实现,它是相当新的,显然仍处于发展初期。请参阅 CUNIT为安藤先生首页

A CUnit implementation that is fairly new, and apparently still in early development. See the CUnit for Mr. Ando homepage.

这个名单上次于2008年3月更新。

This list was last updated in March 2008.

其他:

CMocka是对C与mock对象支持一个测试框架。它易于使用和安装。 CMocka 的官方主页。

CMocka is a test framework for C with support for mock objects. It's easy to use and setup. CMocka official homepage.

标准是一个跨平台的C单元测试框架,支持自动测试报名,测试参数,理论,以及可输出为多种格式,包括TAP和JUnit XML。每个测试在其自己的进程中运行,所以信号和崩溃可以报告,或者如果需要的测试。请参阅标准首页以获取更多信息。

Criterion is a cross-platform C unit testing framework supporting automatic test registration, parameterized tests, theories, and that can output to multiple formats, including TAP and JUnit XML. Each test is run in its own process, so signals and crashes can be reported or tested if needed. See the Criterion homepage for more information.

HWUT是与C.大力支持一般的单元测试工具,它可以帮助创建Makefile中,产生大量的测试用例中最小的迭代表'codeD,沿着状态机行走,生成C存根等。一般的方法是pretty独特:判决是基于好标准输出/标准输出不好。比较函数,虽然是柔性的。因此,可以用于检查任何类型的脚本。它可以被应用到可以制作标准输出的任何语言​​。请参见 HWUT 主页。

HWUT is a general Unit Test tool with great support for C. It can help to create Makefiles, generate massive test cases coded in minimal 'iteration tables', walk along state machines, generate C-stubs and more. The general approach is pretty unique: Verdicts are based on 'good stdout/bad stdout'. The comparison function, though, is flexible. Thus, any type of script may be used for checking. It may be applied to any language that can produce standard output. See HWUT homepage.

这篇关于单元测试C code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆