473,616 Members | 2,973 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 #1
59 12611
Hooyoo wrote:
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.
Like any other new piece of software, start with the smallest example
that compiles and runs, say a TestFixture with single test.
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?
Write the tests first and the members will be added as you require them.
2. What else should I consider apart from checking parameters and
return value?
Side effects.

--
Ian Collins.
Oct 31 '06 #2
Hooyoo wrote:
How to use CPPUnit effectively?
Use UnitTest++. It's much leaner and easier to use:

http://unittest-cpp.sourceforge.net/

CppUnit is stuffed with features you won't need, and they often get in the
way of the few you do.
When I want to use CPPUnit, I always fint it useless and waste my time.
Do you still spend a lot of time debugging? Don't you feel _that's_ a little
more useless and wasteful?
I think that's mainly
because I don't know how to use CPPUnit effectively.
You should write tests for each new line (or two) of the code. Never write
new code without a failing test.

If a test fails unexpectedly, use Undo to revert the code back to the last
state where it passed. This simple trick takes care of nearly all debugging.
1. Should I write test codes for every member function of my class? If
not, which function should be tested?
To make the function exist, you need a test. To make its behavior change,
you need another test. And so on.
2. What else should I consider apart from checking parameters and
return value?
Each test case you write, run it first and see if it fails. The test should
fail for the correct reason. Any kind of code could, in theory, pass the
test, so you should then write just enough code to pass. If the code errs,
it should err on the side of simplicity.

Then write another test to force out the error. These tests, together, will
constrain the innards of that function.

The result works as if the test cases all colluded to constrain all the
function's internal lines, though each test case alone is too simple.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Oct 31 '06 #3

Phlip wrote:
Hooyoo wrote:
How to use CPPUnit effectively?

Use UnitTest++. It's much leaner and easier to use:

http://unittest-cpp.sourceforge.net/
The MS VC project in the zipped source makes me disgusting.
CppUnit is stuffed with features you won't need, and they often get in the
way of the few you do.
When I want to use CPPUnit, I always fint it useless and waste my time.

Do you still spend a lot of time debugging? Don't you feel _that's_ a little
more useless and wasteful?
I think that's mainly
because I don't know how to use CPPUnit effectively.

You should write tests for each new line (or two) of the code. Never write
new code without a failing test.

If a test fails unexpectedly, use Undo to revert the code back to the last
state where it passed. This simple trick takes care of nearly all debugging.
1. Should I write test codes for every member function of my class? If
not, which function should be tested?

To make the function exist, you need a test. To make its behavior change,
you need another test. And so on.
2. What else should I consider apart from checking parameters and
return value?

Each test case you write, run it first and see if it fails. The test should
fail for the correct reason. Any kind of code could, in theory, pass the
test, so you should then write just enough code to pass. If the code errs,
it should err on the side of simplicity.

Then write another test to force out the error. These tests, together, will
constrain the innards of that function.

The result works as if the test cases all colluded to constrain all the
function's internal lines, though each test case alone is too simple.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Oct 31 '06 #4
Binary wrote:
Phlip wrote:
>Hooyoo wrote:
>>How to use CPPUnit effectively?
Use UnitTest++. It's much leaner and easier to use:

http://unittest-cpp.sourceforge.net/
The MS VC project in the zipped source makes me disgusting.
I resemble that remark.
Oct 31 '06 #5
Binary wrote:
> http://unittest-cpp.sourceforge.net/
The MS VC project in the zipped source makes me disgusting.
I'm sure you already were. However...

The authors are quite proud to support various other compilers, including
those targeting embedded platforms.

Or did you expect the project to ship with no project files of any kind?
Don't get me started about Autoconf and the abattoir of eternal torture that
is the Makefile format(s)...

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Oct 31 '06 #6
Phlip wrote:
Binary wrote:
>> http://unittest-cpp.sourceforge.net/
The MS VC project in the zipped source makes me disgusting.

I'm sure you already were. However...

The authors are quite proud to support various other compilers, including
those targeting embedded platforms.

Or did you expect the project to ship with no project files of any kind?
Don't get me started about Autoconf and the abattoir of eternal torture that
is the Makefile format(s)...
HEY - make is beautiful. I use it with MakeXS (I really have to put
that web page back up) but a copy comes with Austria C++.

autoconf on the other hand, well it surprises me just how much it is used.

As for MS project files, they're a disaster as well, if you have a large
number of project files, its very hard to maintain them.
Oct 31 '06 #7

Phlip wrote:
Binary wrote:
http://unittest-cpp.sourceforge.net/
The MS VC project in the zipped source makes me disgusting.

I'm sure you already were. However...

The authors are quite proud to support various other compilers, including
those targeting embedded platforms.

Or did you expect the project to ship with no project files of any kind?
Don't get me started about Autoconf and the abattoir of eternal torture that
is the Makefile format(s)...
Shrug... at least they work on more than one platform/compiler
combination.

Oct 31 '06 #8
Binary wrote:
The MS VC project in the zipped source makes me disgusting.
That's interesting. I looked at the MS VC project. Then I looked in a
mirror. Seems like the project doesn't have any effect on me.

Oct 31 '06 #9
Hooyoo wrote:
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.
This group is about C++. It seems that you don't understand what unit
tests are about. So I'd like to recommend a very good book about unit
testing to you:

Kent Beck: Test Driven Development. By Example. Addison Wesley.

This book isn't about CPPUnit. It isn't even about C++. It uses Java
and JUnit for its examples. But it is very well written and the example
code is very easy to understand.
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?
You will find the answers to these non-C++-related questions in the
book I recommended.
Thanks.
You're welcome

Oct 31 '06 #10

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

Similar topics

46
3496
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
1618
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
3827
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
1832
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
837
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
3570
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
4152
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
1215
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
8203
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
8146
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
8647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8592
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
7121
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
4063
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
4141
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2579
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
1
1759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.