473,699 Members | 2,799 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 12616
jolz wrote:
>>How do I test concurrency?
Easy - run many of them.

And if 1000 passes succedes that means that everything is ok? I don't
tink so.
I tink that would be a bad test.
... For example:
example of bad test removed. I can write bad tests too...
...really mean anything.
Many people beg to differ. Sure, you can write a bogus test, bets are
however that if you don't do it you're likely going to find a problem as
a customer report which is far more costly.
... Real life examples are much more
subtle.
My experience is the opposite.
... Also the same test may work on one comuter + compiler +
operating system (for example test machine) and fail on every other.
Exactly, so run it on a bunch of different test machines. I reccomend a
dual platform development for exactly this reason. Linux-posix + Win32
is a great combination.
It runs about a minute on my computer. If I would have to test this way
all functions in 500000 line application it would take a lot of time.
again - bad test. You have to run a dual CPU or better to run
multithreaded tests. Also your test has too much overhead, you create
new threads all the time. I usually create a parameterized number of
threads make them all arrive at a barrier and then unleash them all at
the same time. Then I run the test with those threads throughout the
entire test.
And usually 1 fuction have more than 1 test.
Notice that single look at the code proves that code is wrong, but
100000 passes of the test gave the illusion that everything is ok.
Again, your clever, write a better test.

This argument sounds like: "Doctor doctor, it hurts when I point a gun
at my foot and shoot". Well, duh !
>
>>How do I test proper excepion handling after disk failure?
Have you app code read/write to an abstracted layer that you can
simulate those kinds of failures.

But this way I have to change my code. Well, it may lead to a better
design, but still the test tests the abstract layer and not the actual
problem.
You can't test every situation all the time, nobody argues that. The
question is, what is the cost/benefit of doing some. Clearly if you
have no tests you're running blind. If you have some tests you're
better off and so on until there is a diminishing return. Maybe you can
use this principle. "If I write a unit test and it finds no bugs, then I
stop and move onto the next project."
>
>>How do I test efficiency of used algorithm?
Run the test on large data sets and limit the execution time.

Remember - first write test, than write code. So how do you guess what
is the correct time? And what happens if test is run on a faster
machine? I guess it will pass every time even is something was broken.
Use common sense at first and be a little conservative. It depends on
the app.
>
Those were only examples. In real life there are much more of those (so
far I think that we agree that gui is not unit testable, and there are
lots of developers that do only gui).
There are frameworks for testing GUI. I'm not familiar with the state
of the art. I was hinting at being careful about being distinct from
function and appearance. I agree that you can't test if something is
aesthetic, but you can test if somthing works.
>
>>Also probanly everybody who write tests spent a lot of time debuging
working code and finding that the mistake was in the test.
So ? The tests can take some time to write but it is far less expensive
and much more useful to find the bugs before it gets to the customer.

But even less expensive is simply looking into the code and thinking
what to do to make it right, not what to do to make some test pass.
Test will pass anyway.
I think you're wrong here. I have yet to meet a programmer that can
write code without bugs.

Nov 2 '06 #31
jolz wrote:
>And don't thread.

So how do I write gui application?
Briefly, sometimes you need threads. Fight them, because they are bad. They
are like 'goto'. Don't thread just because "my function runs too long, and I
want to do something else at the same time". Fix the function so you can
time-slice its algorithm. That overwhelmingly improves your design, anyway.

The tutorials for threads often give lame examples that only need simpler
fixes. The tutorials often don't examine the full rationale for threading.
If you drive with one hand and eat a sandwich with another, you might need a
thread. Internet Explorer probably uses threads. If our apps are simpler, we
shouldn't need them, and should resist adding them until we explore all
possible alternatives.
Do you really write for example
database communicatin from gui thread?
The question here is simple: Why and how does communication block your GUIs
thread?

Winsock, for example, fixed that (for 16-bit Windows without much thread
support) by turning network input into a window message. If you have input
communication, you can often _research_ to find the right function that
multiplexes its events together with your GUI events.

If you can't find such a function, then you must use a thread, and you
should use PostMessage() or similar to send events to your GUI thread. If
you thread, make sure your code in both threads is sufficiently event-driven
that you don't need to abuse your semaphores.

Threading violates encapsulation when one thread must remain "aware" of
another thread's intimate details, just to get something done.
If so, how do you allow user to
stop the operation.
I didn't say "lock the GUI up early and often". I just said "don't thread".
There's a lot of middle ground.
So how do you guess what
is the correct time?

or you set the time comfortably close to what
the code currently does.

What is the purpose of test if I write test so it allways passes?
A test here and there that can't fail is mostly harmless. Note that, under
TDD, you often write tests and show them failing at least once, before
passing them.

The purpose of my time example is to instantly fail if someone "upgrades"
the tested code and exceeds the time limit. They ought to see the failure,
Undo their change, and try again. Even if the test defends nothing, the
upgrades shouldn't be sloppy.
And what about changing hardware? Rewrite all tests?
Nobody said time-test all tests.
Change 1 global
settings and pray that it is changed with correct proportion? Or maybe
make new settings so all test passes?
To continue your digression here, one might ask what we expect to do without
tests when we change 1 global variable (besides not use global variables).
Should we debug every function in our program? Of course not, we just run
out of time. So we debug a few of them, and _then_ we pray.

That is the most common form of implementation, and it is seriously broken.
>But it must pass on every developer machine, too.

Does really tests that run few hours/days are run on all machines in a
company?
Yes, because developers are running all the tests before integrating their
code. If any test fails, they don't submit. So the same tests must pass on
every machine, many times a day.

What do you do before integrating? Spot check a few program features,
manually?
>GUIs are always unit testable. They are just a bad place to start
learning!

I'v seen tester trying to write a gui test.
That is QA, and test-last. That means it's a professional tester, trying to
write a test that will control quality. And she or he is using the program
from the outside, not changing its source to write the test.

That's all downhill from the kind of testing we describe here. And without a
unit test layer, it's bloody impossible. But they keep trying!
Heard about others. It was
allways a lot of work with minor advantages. It was only testing
behaviour. Never how application looks. And it was an easier version -
java gui. I hava no idea how can't be it even worse in language without
gui in a standart.
And that is probably describing Capture/Playback testing, which is the worst
of the lot.

Now if I can write a test, in the same language as the tested code, that
tests how our program drives the database, or the file system, why can't I
write a test that checks how we drive the GUI? What's so special about GUIs?
>Short-term, tests make development faster by avoiding debugging,
including
all the "program in the debugger" that everyone does with modern editors.

Debugger also won't work in any of situations I presented. The fact
that test isn't worse than debugger doesn't mean that it usefull.
That is a different topic. I mean that TDD prevents the need to run the
debugger. Programming teams who switch to TDD routinely report that they
never even turn their debugger on; never set a breakpoint; never inspect a
variable.
I didn't quite get how uml causes bugs. But let's not start another
off-topic from this one.
UML doesn't cause bugs. Drawing a UML diagram, then converting the diagram
to code full of empty classes with no behavior, causes bugs. All the classes
are empty, but they inherit and delegate properly! Then you must debug, over
and over again, to put the behavior in.
>Each and every time
you get a Green Bar, you could integrate and ship your code.

Again the thing that scares me the most. Green = good. Don't think
about anythink else. If it's green so it must work. Well, it doesn't.I
have nothing against tests. Sometimes they are usefull. But they don't
solve all developer's problems.
Nobody said that, so don't extrapolate from it.

Under TDD, sometimes you predict the next Bar will be Red. The point of the
exercise is you constantly predict the next Bar color, and you are almost
always right. Predictability = good. It shows that your understanding of the
code matches what the code actually does.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 2 '06 #32
Phlip wrote:
jolz wrote:

>>>And don't thread.

So how do I write gui application?


Briefly, sometimes you need threads. Fight them, because they are bad. They
are like 'goto'.
Even if you application benefits from concurrency?

I never used goto, but I often use threads and I don't have any issues
with doing TDD with an MT application.

--
Ian Collins.
Nov 2 '06 #33
Ian Collins wrote:
>Briefly, sometimes you need threads. Fight them, because they are bad.
They
are like 'goto'.

Even if you application benefits from concurrency?
If your app benefits from goto, use it. Various techniques have various
cost-benefit ratios.

Like goto, the cost-benefit ratio for threads is known to be suspicious.
They are hard to test for a reason; that's not the unit tests' fault!!

Fight them, by learning how to avoid them, if at all possible. Such research
will generally lead to a better event-driven design. This design, in turn,
will be easy to thread if you then prove the need.
I never used goto, but I often use threads and I don't have any issues
with doing TDD with an MT application.
That's because TDD is not the same thing as a formal QA effort to determine
your defect rate.

And I suspect there are those who have mocked their kernel and CPU just to
put unit tests on their threads!

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 2 '06 #34
Gianni Mariani wrote:
This argument sounds like: "Doctor doctor, it hurts when I point a gun at
my foot and shoot". Well, duh !
Make sure you test the gun first!

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 2 '06 #35
Phlip wrote:
Ian Collins wrote:

>>>Briefly, sometimes you need threads. Fight them, because they are bad.
They
are like 'goto'.

Even if you application benefits from concurrency?


If your app benefits from goto, use it. Various techniques have various
cost-benefit ratios.
I still think the analogy is too strong, I can't think of any situation
where I'd resort to goto.
Like goto, the cost-benefit ratio for threads is known to be suspicious.
They are hard to test for a reason; that's not the unit tests' fault!!

Fight them, by learning how to avoid them, if at all possible. Such research
will generally lead to a better event-driven design. This design, in turn,
will be easy to thread if you then prove the need.
Most of the work I do does a lot of processing and I/O. The
applications invariably run on multi-core systems. Keeping all the
cores busy get the job done quicker.

While they can either be abused or used inappropriately , threads can
often simplify a design.
>
>>I never used goto, but I often use threads and I don't have any issues
with doing TDD with an MT application.


That's because TDD is not the same thing as a formal QA effort to determine
your defect rate.
I didn't say it was.
And I suspect there are those who have mocked their kernel and CPU just to
put unit tests on their threads!
I wouldn't go that far, but mocking the thread library to run the units
tests in a single threaded application is a useful technique. From my
experience, MT unit tests are unnecessary and tend to end in tears.

--
Ian Collins.
Nov 2 '06 #36
Ian Collins wrote:
I still think the analogy is too strong, I can't think of any situation
where I'd resort to goto.
Not even "goto another stack and CPU context"?

That's what a thread does; goes from the middle of one function to the
middle of another.
Most of the work I do does a lot of processing and I/O. The
applications invariably run on multi-core systems. Keeping all the
cores busy get the job done quicker.
My hostility to thread abuse dates from the 1980s, with single-processor
machines. I worked for many years at a shop stuck with a design invented by
a consultant who read the lame tutorials I mention, and used threads where
he should have used good structure. The threads enabled the bad structure,
which should have been fully event-driven. I got to see the drag this
imposed on our product - and all the thread bugs that went with it.

Granted, the bad structure wasn't directly the threads' fault. But a good
structure could have made the threads easier to live with - or replace!

On a modern multi-context CPU, don't thread and then lock everything down.
You will naturally have a single-threaded, multi-CPU application!

Yet if those threads are indeed independent of each other, then you merely
have a multi-process situation. That's very different from the juggling-act
you get if you use threads for trivial reasons, such as GUI concurrency!
>That's because TDD is not the same thing as a formal QA effort to
determine
your defect rate.
I didn't say it was.
You can TDD the functions your threads call. I suspect that writing a
TDD-style test case that juggles threads is very hard, so I would slack off
on that. (It's not strictly required to generate the code.) So TDD's
incidental power of QA will suffer in this situation.
>And I suspect there are those who have mocked their kernel and CPU just
to
put unit tests on their threads!
I wouldn't go that far, but mocking the thread library to run the units
tests in a single threaded application is a useful technique. From my
experience, MT unit tests are unnecessary and tend to end in tears.
And still not a reason not to write unit tests! ;-)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 2 '06 #37
Phlip wrote:
Ian Collins wrote:

>>I still think the analogy is too strong, I can't think of any situation
where I'd resort to goto.


Not even "goto another stack and CPU context"?
Boy some people like their hairs split pretty fine :)
>
Yet if those threads are indeed independent of each other, then you merely
have a multi-process situation.
With all the benefits and pitfalls of a shared data model.
>
>>>And I suspect there are those who have mocked their kernel and CPU just
to
put unit tests on their threads!

I wouldn't go that far, but mocking the thread library to run the units
tests in a single threaded application is a useful technique. From my
experience, MT unit tests are unnecessary and tend to end in tears.


And still not a reason not to write unit tests! ;-)
Indeed, but I'd advise against writing MT units tests. As you have
pointed out before, that level of testing doesn't help with TDD and is
best left to the acceptance tests.

--
Ian Collins.
Nov 2 '06 #38
Ian Collins wrote:
....
Indeed, but I'd advise against writing MT units tests. As you have
pointed out before, that level of testing doesn't help with TDD and is
best left to the acceptance tests.
Unless you're designing something is multi threaded by design. For
example, If the type is performing some kind of asynchronous event
management, it's kind of useless to write a TDD unit test for it that
does not show the MT aspects...
Nov 2 '06 #39
Gianni Mariani wrote:
Ian Collins wrote:
....
>Indeed, but I'd advise against writing MT units tests. As you have
pointed out before, that level of testing doesn't help with TDD and is
best left to the acceptance tests.


Unless you're designing something is multi threaded by design. For
example, If the type is performing some kind of asynchronous event
management, it's kind of useless to write a TDD unit test for it that
does not show the MT aspects...
You can test the logic without running in an MT environment.

Same with testing something like a signal handler or interrupt service
routine, you don't have to send an event to test the code. You know the
underlying OS/hardware will deliver the event, your job is to build the
code that processes it.

--
Ian Collins.
Nov 2 '06 #40

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
8687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8615
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
9034
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...
0
8883
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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?
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.