473,699 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use CPPUnit effectively?

How to use CPPUnit effectively?
When I want to use CPPUnit, I always fint it useless and waste my time.
I think that's mainly
because I don't know how to use CPPUnit effectively. So if somebody
here has some experience,
please share it to me.
And also I expect answers to these questions:
1. Should I write test codes for every member function of my class? If
not, which function should be tested?
2. What else should I consider apart from checking parameters and
return value?

Thanks.

Oct 31 '06
59 12617
Gianni Mariani wrote:
Hiding the MT nature of a service does not help you design it properly !
You are correct that TDD is _a_ design technique, but it's not the only one.
MT requires more than emergent design. (Not much more, as Ron Jeffries's
paper noted, for one narrow situation.)
>If we are not writing a kernel, we don't need to TDD its event systems.
We won't refactor our kernel, so gaps in our test coverage are very low
risk.

I disagree. I think this is why I have seen so many abortions of MT code,
because they don't take into account the big 3:

1. resource deadlock (not just mutexes)
2. reliable destruction
3. reliable event management
Right. That's neither TDD's fault, nor a good target for TDD's power.
>>Show me what your timer test code looks like ?

TEST_(TestDialo g, SetTimer)
{
CButton slowButton = m_aDlg.GetDlgIt em(IDC_SLOW_OPE RATION);
slowButton.Send Message(BM_CLIC K);
BOOL thereWasaTimerT oKill = m_aDlg.KillTime r(0);
CPPUNIT_ASSERT( thereWasaTimerT oKill);
}

Not a very useful timer interface, how can I reset the timer ? Can I
safely delete my client and see the timer get deregistered automatically?
Can I set the timer to an absolute time or an interval?
I didn't invent the Win32 timer interface. And we note with sadness that
even high-end OS APIs are often not designed for testing.
The point is, you can't design something using TDD if you don't show how
it's done.
Yes you can, for known algorithms, and for the majority of new code. Legacy
code considerations always interfere. MT is just one of the culprits. Any
kind of pre-existing code will taint the purity of your emergent design. All
this is still no excuse not to TDD your code, and not to emerge your own
designs.
If your interface is dealing with MT issues, there really is little point
in not doing an MT unit test for the purposes on TDD.
Can I get such a test to fail in a way that directs me to write new code?

Regardless of my reluctance to TDD the MT stuff, I suspect the answer is
yes!

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 3 '06 #51
Ian Collins wrote:
Gianni Mariani wrote:
>The point is, you can't design something using TDD if you don't show how
it's done. If your interface is dealing with MT issues, there really is
little point in not doing an MT unit test for the purposes on TDD.

I think we'll have to agree to disagree on this point, I still think you
can't write an MT unit test in a TDD context. Why? Because it's all
but impossible to write a single pass MT test that has a 100%
predictable outcome. There are too many variables, how busy the machine
is, which thread starts first, is there more than one CPU available when
the test runs... So you end up getting unexpected and often
unrepeatable test failures.
I thought you argued earlier that unit tests for the purposes of design?
As for your unpredictabilit y argument, umm what are you talking about.
MT code had better have a predictable outcome otherwise there is no
point in MT at all.

>
But you can TDD the logic of an MT object and use a separate Monte Carlo
type acceptance stress test for the MT functionality.
Yes. I've always seen it happen that way, TDD unit test followed by a
more rigorous test. What I am saying is that in the limited number of
interfaces that are MT specific, the TDD unit test case/s should
encompass the complexities of MT, otherwise you're design is likely to
come out incomplete.

Nov 3 '06 #52
Phlip wrote:
Gianni Mariani wrote:
>Hiding the MT nature of a service does not help you design it properly !

You are correct that TDD is _a_ design technique, but it's not the only one.
MT requires more than emergent design. (Not much more, as Ron Jeffries's
paper noted, for one narrow situation.)
Yes. The only point I am trying to defend is "in the limited number of
cases where the design is inherently MT, the TDD test case will help you
design better if it demonstrates how to manage it's MT nature of the
design". As for how to design as a whole, that a far more involved
discussion.
>
>>If we are not writing a kernel, we don't need to TDD its event systems.
We won't refactor our kernel, so gaps in our test coverage are very low
risk.
I disagree. I think this is why I have seen so many abortions of MT code,
because they don't take into account the big 3:

1. resource deadlock (not just mutexes)
2. reliable destruction
3. reliable event management

Right. That's neither TDD's fault, nor a good target for TDD's power.
The point I'm trying to make is that this can be considered unless the
TDD test case shows what how the problem is solved.
>
>>>Show me what your timer test code looks like ?
TEST_(TestDialo g, SetTimer)
{
CButton slowButton = m_aDlg.GetDlgIt em(IDC_SLOW_OPE RATION);
slowButton.Send Message(BM_CLIC K);
BOOL thereWasaTimerT oKill = m_aDlg.KillTime r(0);
CPPUNIT_ASSERT( thereWasaTimerT oKill);
}
Not a very useful timer interface, how can I reset the timer ? Can I
safely delete my client and see the timer get deregistered automatically?
Can I set the timer to an absolute time or an interval?

I didn't invent the Win32 timer interface. And we note with sadness that
even high-end OS APIs are often not designed for testing.
"Testabilit y" is a primary deliverable.
>
>The point is, you can't design something using TDD if you don't show how
it's done.

Yes you can, for known algorithms, and for the majority of new code. Legacy
code considerations always interfere. MT is just one of the culprits. Any
kind of pre-existing code will taint the purity of your emergent design. All
this is still no excuse not to TDD your code, and not to emerge your own
designs.
That's what wrapping code in abstractions is for.
>
> If your interface is dealing with MT issues, there really is little point
in not doing an MT unit test for the purposes on TDD.

Can I get such a test to fail in a way that directs me to write new code?
Yes. I tend to make less mistakes today but just the act of writing the
test case usually helps me realize the more elegant ways of doing things.
>
Regardless of my reluctance to TDD the MT stuff, I suspect the answer is
yes!
MT TDD unit tests should be limited to just the designs that are MT in
nature. e.g. Timers, asynchronous comms layers, low level MT facilities
like threadpools.

I might be wrong but I think we're not saying anything different.
Nov 3 '06 #53
Gianni Mariani wrote:
Ian Collins wrote:
>Gianni Mariani wrote:
>>The point is, you can't design something using TDD if you don't show how
it's done. If your interface is dealing with MT issues, there really is
little point in not doing an MT unit test for the purposes on TDD.


I think we'll have to agree to disagree on this point, I still think you
can't write an MT unit test in a TDD context. Why? Because it's all
but impossible to write a single pass MT test that has a 100%
predictable outcome. There are too many variables, how busy the machine
is, which thread starts first, is there more than one CPU available when
the test runs... So you end up getting unexpected and often
unrepeatable test failures.


I thought you argued earlier that unit tests for the purposes of design?
They are, the design of the logic.
As for your unpredictabilit y argument, umm what are you talking about.
MT code had better have a predictable outcome otherwise there is no
point in MT at all.
I was referring to tests that start threads. On my last project we
started with several of these, by the end they were removed and the
treading layer tested in its own Monte Carlo type test harness.
>>
But you can TDD the logic of an MT object and use a separate Monte Carlo
type acceptance stress test for the MT functionality.


Yes. I've always seen it happen that way, TDD unit test followed by a
more rigorous test. What I am saying is that in the limited number of
interfaces that are MT specific, the TDD unit test case/s should
encompass the complexities of MT, otherwise you're design is likely to
come out incomplete.
Maybe I should revisit TDD and threads. I've been bitten too many times
over the years by tests with multiple threads that I've grown accustomed
to using a different test style for that limited number of interfaces.
It may also be that I've implemented them so many times, I don't have to
design any more!

--
Ian Collins.
Nov 3 '06 #54
Ian Collins wrote:
Gianni Mariani wrote:
....
>>
Yes. I've always seen it happen that way, TDD unit test followed by a
more rigorous test. What I am saying is that in the limited number of
interfaces that are MT specific, the TDD unit test case/s should
encompass the complexities of MT, otherwise you're design is likely to
come out incomplete.
Maybe I should revisit TDD and threads. I've been bitten too many times
over the years by tests with multiple threads that I've grown accustomed
to using a different test style for that limited number of interfaces.
It may also be that I've implemented them so many times, I don't have to
design any more!
They are definitely limited in number. e.g. I would not do an MT TDD
test for a matrix library (as an example), even if the library used
threads to parallelize. Unless of course it needed an asynchronous
termination interface to terminate long running computations reliably.

A nice threading or pool interface makes life easier.
Nov 3 '06 #55
Gianni Mariani wrote:
"Testabilit y" is a primary deliverable.
Yay! Now watch me try to bill hours for it! (To a client familiar with
hack-n-slash web programming ;-)
I might be wrong but I think we're not saying anything different.
I noticed that a while ago but I kept going...

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 3 '06 #56
VJ
Phlip wrote:
VJ wrote:

>>We are using http://cxxtest.sourceforge.net/guide.html and it is good and
easy to understand


I don't understand the brief amount of documentation I read.

Given test<3>, do I guess right that we have to increment that 3 by hand,
each time we

I want to smoke crack while coding, and having to remember what number I'm
up to interferes with my lifestyle. I can't even think of a macro that fixes
this (with a compile-time constant).

So does cxxtest really make me increment that number? Or should I, like,
read more of the documentation before passing judgement?
Not sure what you are talking about - I have not read their documentation

You call a function with specific parameters, and check what it outputs

Does a unit test library you are using increment that number for you?
Nov 3 '06 #57
VJ wrote:
http://cxxtest.sourceforge.net/guide.html
Not sure what you are talking about - I have not read their documentation
I will start again from scratch.

I'm looking for a pattern called "Test Collector".

cxxtest implements it using a Perl script:

cxxtestgen.pl --error-printer -o runner.cpp MyTestSuite.h

That reads the source, pulls out every function named /test*/, and writes
runner.cpp to call them all.

(Parentheticall y, I propose that going to another language just to avoid
macros is kind'a pathetic...)

That is still better than the CppUnit system of making you write the name of
each test case twice. (For TDD, test cases must be _absurdly_ easy to add!)

I seem to recall recently reading the documentation of a test runner that
uses templates to do Test Collector. Maybe not; I can't find them on the
above page. No worries.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 3 '06 #58
Phlip wrote:
Gianni Mariani wrote:
>"Testability " is a primary deliverable.

Yay! Now watch me try to bill hours for it! (To a client familiar with
hack-n-slash web programming ;-)
That's ok, keep on milking when they need all those urgent customer
fixes ... sad
>
>I might be wrong but I think we're not saying anything different.

I noticed that a while ago but I kept going...
Nov 3 '06 #59
Phlip wrote:
....
I seem to recall recently reading the documentation of a test runner that
uses templates to do Test Collector. Maybe not; I can't find them on the
above page. No worries.
Austria C++'s unit test framework uses the Austria C++ generic factory
to collect all the unit tests into one place at startup. One of the
nice things about this is that you can place your unit tests entirely in
their own anonymous namespace so you can more-or-less cut-n-paste a test
from one file to the other and not have to worry about namespace
collisions. Depending on your debugger, you may or may not want to do this.
Nov 3 '06 #60

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

Similar topics

46
3508
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved by pointer in C++, is there such way in Python? Thansk in advance. J.R.
0
1619
by: Roy Smith | last post by:
I'm writing a network application in C++, using CppUnit for unit testing. I'm thinking of forking a subprocess to run tcpdump in some of my unit tests to watch actual packets on the wire as they are transmitted and received. Has anybody done anything like this? Any words of advice (or discouragement)?
2
3828
by: Scott | last post by:
I'm trying to run cppunit on my system under Mac OS X 10.3.3 with Xcode, and I'm getting the following error when I try to run the program: ZeroLink: unknown symbol '__ZN7CppUnit8TestCase3runEPNS_10TestResultE' prog has exited due to signal 6 (SIGABRT). Any idea why I would be seeing this? The program compiles with no problems, it just looks like it can't find a method it needs. I've
9
1968
by: Steven T. Hatton | last post by:
I finally got this thing to build. There's something to be said for using the release of the cvs image sometimes. :-/ I started reading the docs, and this example struck me as a fundamentally bad design for C++. Perhaps it's not bad design in the sense that it will fail, or that it can't be maintained. But there seems to be something fundamentally un-C++ about this. Does anybody else see what I'm talking about here? class...
1
1833
by: To Forum | last post by:
hi, After searching around with google, I have not reach a final answer for my problem with installation with CPPUNIT. 1/ how can I register the dll file in VC7, please tell me in detail 2/ have any one succeed with DSPPlugin. I have found on the page of CPPUNIT a partial answer http://cppunit.sourceforge.net/cgi-bin/moin.cgi/BuildingCppUnit1 but still, I wonder if anyone have a better solution. Thanks TF
0
842
by: skip | last post by:
Manish> It does not work. I had already tried this earlier. Manish> Please suggest some other solutions. Manish> Also, I would like to see the stack from where the exception Manish> started. Manish, You made it extremely difficult for anyone to respond intelligently to your message. It has at least the following problems:
3
3575
by: Belebele | last post by:
Suppose I want to test several implementations of the same protocol (interface with clearly defined semantics) using cppUnit. How to reuse the test that checks the semantics? Take, for example, the simple SetterGetter interface and the even simpler implementations Impl1 and Impl2. class SetterGetter { SetterGetter& operator=(SetterGetter const& ); // Not Implemented
4
4154
by: romcab | last post by:
Hi guys, I'd been searching about CPPUnit and I can't find a very good source about it. At first I thought it was a software that I need to install but found out that what I have is the source code. I want to know if i need to build it and how can I use this one. Hope you can help me guys.
0
1217
by: Jane Prusakova | last post by:
Hello, I would like to test some of the classes for being proper objects, the kind of tests that the Orthodox<MyClassextension of CppUnit library does. However, I can't figure out how to get these tests to run. Can somebody point me to an example, or show how to add these tests to the test runner program? Using CppUnit 1.12 on FreeBSD, gcc version 3.4.2.
0
8617
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.