使用功能模拟进行单元测试 [英] Unit Testing With Function Mocking
问题描述
目前,我正在使用CUnit作为单元测试工具。但它确实缺少一个
的东西:函数嘲弄。换句话说,更改
在下级例程中实际调用的内容,以便测试函数
具有可预测的行为。
我知道CGreen有这种能力,但似乎没有工作
Cygwin。此外,它是另一种投入时间的工具。
有没有办法在CUnit中获得此功能?或者,是否有一个比CUnit或CGreen更好的工具?
欢迎任何建设性的想法。
谢谢,
-T
" ; gamename" < na *************** @ yahoo.com写了留言
目前,我正在使用CUnit作为单元测试工具。但它确实缺少一个
的东西:函数嘲弄。换句话说,更改
在下级例程中实际调用的内容,以便测试函数
具有可预测的行为。
我知道CGreen有这种能力,但似乎没有工作
Cygwin。此外,它是另一种投入时间的工具。
有没有办法在CUnit中获得此功能?或者,是否有一个比CUnit或CGreen更好的另一个工具?
欢迎任何建设性的想法。
我会怀疑你能用
自动工具有效地模拟一个函数。怎么知道什么是什么,什么不是副作用
与电话一致?
我赞成单元测试,但是我我们不认为它们是灵丹妙药。它好像是b $ b似乎你可能会达到开发的地步,这个想法
开始崩溃。
-
免费游戏和编程的好东西
HTTP:/ /www.personal.leeds.ac.uk/~bgy1mm
gamename写道:
目前,我正在使用CUnit作为单元测试工具。但它确实缺少一个
的东西:函数嘲弄。换句话说,更改
在下级例程中实际调用的内容,以便测试函数
具有可预测的行为。
我知道CGreen有这种能力,但似乎没有工作
Cygwin。此外,它是另一种投入时间的工具。
有没有办法在CUnit中获得此功能?或者,是否有一个比CUnit或CGreen更好的另一个工具?
欢迎任何建设性的想法。
你应该可以逃避这样的事情:
#include< stdio.h>
static int printf(const char * fmat,...){return 0; }
int main(无效){
int n;
printf("%d \ n",n);
返回0;
}
-
伊恩柯林斯
gamename写道:
目前,使用I''m CUNIT作为一个单元测试工具。但它确实缺少一个
的东西:函数嘲弄。换句话说,改变在从属例程中真正调用的内容,以便测试的函数是否具有可预测的行为。
我即将开始使用单元测试框架(选择
,然后可能修改)。作为研究的一部分,我在一些使用嵌入式应用程序单元测试的论文中运行了
< http://atomicobject.com/pages/Papers> 。我记得,作者使用
单独的文件作为应用程序和测试存根。他们可能有相同名称的
,并且位于不同的目录中,有一个机制可以选择特定的包含文件,和/或使用不同的链接
命令用于链接存根版本。
-
Thad
Hi,
Currently, I''m using CUnit as a unit test tool. But there is one
thing it really lacks: function mocking. In other words, changing
what really gets called in subordinate routines so that a function
being tested has predictable behavior.
I know that CGreen has this ability, but it doesn''t seem to work on
Cygwin. Also, its yet-another-tool to invest time on .
Is there any way to get this functionality in CUnit? Or, is there a
another tool that does a better job than CUnit or CGreen?
Any constructive ideas welcome.
Thanks,
-T
"gamename" <na***************@yahoo.comwrote in messageCurrently, I''m using CUnit as a unit test tool. But there is one
thing it really lacks: function mocking. In other words, changing
what really gets called in subordinate routines so that a function
being tested has predictable behavior.
I know that CGreen has this ability, but it doesn''t seem to work on
Cygwin. Also, its yet-another-tool to invest time on .
Is there any way to get this functionality in CUnit? Or, is there a
another tool that does a better job than CUnit or CGreen?
Any constructive ideas welcome.
I''d be sceptical that you can effectively mock up a function with an
automatic tool. How does it know what is and what is not a side-effect
consistent with the call?
I am all in favour of unit tests, but I don''t see them as a panacea. It
seems to be you might be reaching the point in development where the idea
begins to break down.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
gamename wrote:Hi,
Currently, I''m using CUnit as a unit test tool. But there is one
thing it really lacks: function mocking. In other words, changing
what really gets called in subordinate routines so that a function
being tested has predictable behavior.
I know that CGreen has this ability, but it doesn''t seem to work on
Cygwin. Also, its yet-another-tool to invest time on .
Is there any way to get this functionality in CUnit? Or, is there a
another tool that does a better job than CUnit or CGreen?
Any constructive ideas welcome.
You should be able to get away with something like this:
#include <stdio.h>
static int printf( const char* fmat, ...) { return 0; }
int main ( void ) {
int n;
printf( "%d\n", n );
return 0;
}
--
Ian Collins.
gamename wrote:
Currently, I''m using CUnit as a unit test tool. But there is one
thing it really lacks: function mocking. In other words, changing
what really gets called in subordinate routines so that a function
being tested has predictable behavior.I am just about to start working with a unit test framework (to be
chosen, then possibly modified). As part of the research, I have run
across some papers of using unit testing for embedded applications at
<http://atomicobject.com/pages/Papers>. As I recall, the author uses
separate files for the application and test stubs. They might have the
same name and reside in a different directory, have a mechanism for
selecting a particular include file, and/or using different linkage
commands for linking the stub version.
--
Thad
这篇关于使用功能模拟进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!