Stubbing in cxxtest

322 views
Skip to first unread message

Arjun Suresh Raji

unread,
Jun 11, 2014, 3:00:12 AM6/11/14
to cxxtes...@googlegroups.com
Hi,
The way I see how test cases are written it feels that we are testing the interfaces through __arguments__. If that is the only case cxxtest is used wouldn't there be a lot of GAPs in our tests?
Is there a mechanism to stub functions while using cxxtest.

If not could you please suggest any other FOSS tool that could help me in achieving this
--
regards,
Arjun S R

Karen Morrissey

unread,
Jun 11, 2014, 6:57:51 PM6/11/14
to cxxtes...@googlegroups.com
What do you mean by "FOSS"?

As for stub functions, read the CxxTest documentation section on Mock Objects. As pointed out in "xUnit Test Patterns" by Gerard Meszaros, code needs to accommodate testability. That means calling global functions in a way that stubs can be plugged in and also using "glue" classes that can wrap production classes/functions in real code and provide test-oriented alternative classes in unit test programs.

Often, according to Meszaros, to be able to unit test legacy code effectively, it will be necessary to change the legacy code some. Many times, for example, I have written test-oriented derived classes that make private/protected functions of the base class public, so that the unit tests can exercise them directly.

Arjun Suresh Raji

unread,
Jun 12, 2014, 4:23:15 AM6/12/14
to cxxtes...@googlegroups.com


On Thursday, June 12, 2014 4:27:51 AM UTC+5:30, Karen Morrissey wrote:
What do you mean by "FOSS"?
What I meant was Free and Open Source Softwares 

As for stub functions, read the CxxTest documentation section on Mock Objects. As pointed out in "xUnit Test Patterns" by Gerard Meszaros, code needs to accommodate testability. That means calling global functions in a way that stubs can be plugged in and also using "glue" classes that can wrap production classes/functions in real code and provide test-oriented alternative classes in unit test programs.

Often, according to Meszaros, to be able to unit test legacy code effectively, it will be necessary to change the legacy code some. Many times, for example, I have written test-oriented derived classes that make private/protected functions of the base class public, so that the unit tests can exercise them directly.

Thanks for the input. I will check and get back if I have any doubts. 

Arjun Suresh Raji

unread,
Jun 14, 2014, 1:57:45 PM6/14/14
to cxxtes...@googlegroups.com

Hi Karen,
Thanks for your reply. What I meant by FOSS was free and open source software.

For stubbing, I believe there is going to be a lot of effort. I will get back after reading the mock section and related samples.

--
You received this message because you are subscribed to a topic in the Google Groups "CxxTest Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cxxtest-forum/P4rIr7JOcMY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cxxtest-foru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arjun Suresh Raji

unread,
Jun 16, 2014, 3:43:33 AM6/16/14
to cxxtes...@googlegroups.com

On 12-Jun-2014 4:27 am, "Karen Morrissey" <kamor...@kamorrissey.com> wrote:
What do you mean by "FOSS"?

As for stub functions, read the CxxTest documentation section on Mock Objects. As pointed out in "xUnit Test Patterns" by Gerard Meszaros, code needs to accommodate testability. That means calling global functions in a way that stubs can be plugged in and also using "glue" classes that can wrap production classes/functions in real code and provide test-oriented alternative classes in unit test programs.

Often, according to Meszaros, to be able to unit test legacy code effectively, it will be necessary to change the legacy code some. Many times, for example, I have written test-oriented derived classes that make private/protected functions of the base class public, so that the unit tests can exercise them directly.

First, sorry for embedding a picture inline with mail.
I went through the cxxtest samples for Mock. I have made up a diagram in short. Correct me if I am wrong.
Blocks in yellow background are things to be modified or added
Blocks in green background are NOTES
Blocks in blue are actual code and test suite class




Apparently there will be minimum 5 files added in my example. Is my understanding correct ?

Arjun Suresh Raji

unread,
Jun 16, 2014, 5:22:47 AM6/16/14
to cxxtes...@googlegroups.com
Hi,
Cxxtest mandates us to change the application code so as to do unit testing by making it call
"T::function_that_can_be_stubbed" instead of the actual "function_that_can_be_stubbed."

However, if the code that I am debugging is "C" code. How would I make it call similar to it. C does not have scope resolution operation AFAIK.
Kindly help me in this.


Arjun Suresh Raji

unread,
Jun 19, 2014, 6:11:27 AM6/19/14
to cxxtes...@googlegroups.com
Any update on this?

Karen Morrissey

unread,
Jun 19, 2014, 10:14:28 AM6/19/14
to cxxtes...@googlegroups.com
I'm rusty as far as mixing C & C++ code. I know there's a C++ declaration you can use so that you are accessing a C function symbol.

Ad for CxxTest requiring a rewrite for unit testing, it isn't CxxTest that causes this. It is rewriting needed to make the code unit testable. One thing to try to balance: are you sure the functions you're trying to sub out really need to be stubbed out. The answer isn't always simple, so I don't have any advice as far as how to judge that.

Karen A. Morrissey
Author, Fisher King: Percival's Descent, a novel
720-308-4368 mobile
303-744-0047 fax
kamorrissey at kamorrissey.com
www.kamorrissey.com
www.facebook.com/karen.a.morrissey
 



--
Reply all
Reply to author
Forward
0 new messages