Re: Unit Testing With Function Mocking



Jack Klein wrote:
On Sat, 17 Mar 2007 11:30:59 +1300, Ian Collins <ian-news@xxxxxxxxxxx>
wrote in comp.lang.c:


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; }


No guarantees, the behavior is specifically undefined.

Good point, printf was a bad example.

I was just illustrating that a function declared in a header can be
substituted with (overloaded by?) a static function.

--
Ian Collins.
.



Relevant Pages

  • Re: Unit Testing With Function Mocking
    ... I'm using CUnit as a unit test tool. ... thing it really lacks: function mocking. ... Is there any way to get this functionality in CUnit? ... int main { ...
    (comp.lang.c)
  • Unit Testing With Function Mocking
    ... I'm using CUnit as a unit test tool. ... thing it really lacks: function mocking. ... its yet-another-tool to invest time on. ... Is there any way to get this functionality in CUnit? ...
    (comp.lang.c)
  • Re: Unit Testing With Function Mocking
    ... what really gets called in subordinate routines so that a function ... being tested has predictable behavior. ... Is there any way to get this functionality in CUnit? ... I'd be sceptical that you can effectively mock up a function with an automatic tool. ...
    (comp.lang.c)
  • Re: Unit Testing With Function Mocking
    ... thing it really lacks: function mocking. ... what really gets called in subordinate routines so that a function ... Is there any way to get this functionality in CUnit? ... printf was a bad example. ...
    (comp.lang.c)