测试code用C C ++ [英] testing code in C C++

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

问题描述

我不知道你们怎么每次测试code你code一点,针对不同层次的测试:单元测试,集成测试,...

I don't know how you guys test your code every time you code a little and for different levels of testing: unit testing, Integration testing, ...

例如,单元测试,你只是写一个函数,你写另一个一整套的主要功能和Makefile来测试它?或者你修改你的项目来测试该功能的主要功能。或者你只是运行在调试您的项目,在函数即将被称为停止并修改其参数的值?

For example, for unit testing a function you just wrote, do you write another whole set of main function and Makefile to test it? Or do you modify the main function of your project to test the function. Or do you just run your project under debugging, and stop at where the function is about to be called and modify the values of its arguments?

我相信一定是大多数人都使用,只有我不知道的一些方便的常用方式。

I believe there must be some convenient and common ways that most people are using and only I am not aware of.

推荐答案

的xUnit是单元测试模块系列。 x由为框架的使用的语言字母代替。该系列目前包括:

xUnit is a family of unit testing modules. x is replaced by a letter for the language of framework used. The family currently consists of:

  • CUnit (for C)
  • CppUnit
  • NUnit (.NET)
  • EmbUnit ; embedded unit test for C

我在使用CppUnit的效果也不错的项目合作。最近,我一直在努力,这在自动构建环境(即哈德森)集成和我遇到许多障碍来了。

I've worked in projects using CppUnit with good results. Recently I've tried to integrate this in an automatic build environment (i.e. Hudson) and I came across many obstacles.

在理想情况下,构建自动生成并运行单元测试。在此情况下,code为从测试环境中运行(并且因此具有它自己的主循环)。在我的情况的额外复杂的是,我与嵌入式系统工作;的printf并不总是可能的。我希望,如果你在PC上运行,库尼特和CppUnit的可以帮助你很多实现良好的单元测试。请看看如何使用结果;持续集成系统会增加你的效率刍议很多。

Ideally, the build automatically builds and runs the unit tests. In that case, code is run from the test environment (and thus has it's own main loop). An extra complication in my case is that I work with embedded systems; printf is not always possible. I expect that if you run on PC, CUnit and CppUnit can help you a lot to implement good unit testing. Please look at how to use the results; a continuous integration system will increase your effiency a lot.

另一个值得给看看框架是。它依赖于C99(微软从来没有实施,但是对于GCC它是伟大的!)

Another framework worth to give a look is Maestra. It relies on C99 (which Microsoft has never implemented, but for gcc it is great!)

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

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