473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unit Testing With Function Mocking

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

Mar 16 '07 #1
10 5749

"gamename" <na***************@yahoo.comwrote in message
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.
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

Mar 16 '07 #2
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.
Mar 16 '07 #3
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
Mar 17 '07 #4
On Sat, 17 Mar 2007 11:30:59 +1300, Ian Collins <ia******@hotmail.com>
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.

"7.1.3 Reserved identifiers

Each header declares or defines all identifiers listed in its
associated subclause, and optionally declares or defines identifiers
listed in its associated future library directions subclause and
identifiers which are always reserved either for any use or for use as
file scope identifiers.

[snip]

Each identifier with file scope listed in any of the following
subclauses (including the future library directions) is reserved for
use as a macro name and as an identifier with file scope in the same
name space if any of its associated headers is included."

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 17 '07 #5
Jack Klein wrote:
On Sat, 17 Mar 2007 11:30:59 +1300, Ian Collins <ia******@hotmail.com>
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.
Mar 17 '07 #6
On Mar 17, 7:53 am, Ian Collins <ian-n...@hotmail.comwrote:
Jack Klein wrote:
On Sat, 17 Mar 2007 11:30:59 +1300, Ian Collins <ian-n...@hotmail.com>
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.
If thats the case, then
#define printf (void)

should do the job without trampling all over the standard
library.
Mar 17 '07 #7
On Mar 16, 8:39 pm, Thad Smith <ThadSm...@acm.orgwrote:
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
Thanks Thad. That's a good start.

Mar 18 '07 #8
On Mar 17, 2:59 pm, "goose" <r...@webmail.co.zawrote:
On Mar 17, 7:53 am, Ian Collins <ian-n...@hotmail.comwrote:
Jack Klein wrote:
On Sat, 17 Mar 2007 11:30:59 +1300, Ian Collins <ian-n...@hotmail.com>
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.

If thats the case, then
#define printf (void)

should do the job without trampling all over the standard
library.
Rather than redifining printf (to use this example), could there be a
way to define each function entry address as a handle? In other
words, link in a "shim" layer that allows the user to change the
address of printf?

Thoughts?
-T

Mar 18 '07 #9
gamename wrote:
>
Rather than redifining printf (to use this example), could there be a
way to define each function entry address as a handle? In other
words, link in a "shim" layer that allows the user to change the
address of printf?
Possibly, but that depends on your platform. Try asking this on a
platform specific group.

--
Ian Collins.
Mar 18 '07 #10
On Mar 18, 12:35 pm, Ian Collins <ian-n...@hotmail.comwrote:
gamename wrote:
Rather than redifining printf (to use this example), could there be a
way to define each function entry address as a handle? In other
words, link in a "shim" layer that allows the user to change the
address of printf?

Possibly, but that depends on your platform. Try asking this on a
platform specific group.

--
Ian Collins.
Will do. Thanks.

-T

Mar 19 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: steven | last post by:
Hi, Anyone was using pmock for unit testing with python? I met a problem and hope someone to help me. For short, the pmock seems can not mock a iterator object. For example, the tested...
38
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
3
by: Water Cooler v2 | last post by:
Here's my understanding as of now. If I were writing a function bool IsValidContact(Offerer objOfferer, Accepter objAccepter, TermsAndConditions objTermsAndConditions); Before writing the...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
5
by: Ben Finney | last post by:
Howdy all, PEP 299 <URL:http://www.python.org/dev/peps/pep-0299details an enhancement for entry points to Python programs: a module attribute (named '__main__') that will be automatically called...
20
by: earthwormgaz | last post by:
Hello, I'm after doing some C++ unit testing, I'm using CppUnit. I like the look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no good to me sadly. So, I have class A, and it...
0
by: mo.sparrow | last post by:
The advantages of unit testing are well known, giving development teams a safety net to facilitate change, ease integration and supply live documentation.Unit testing of small logical code is quite...
2
by: mo.sparrow | last post by:
Typemock Isolator – A powerful mocking framework for .NET unit testing and Test Driven Development (in Visual Studio). http://www.typemock.com/learn_about_typemock_isolator.html NUnit - A...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.