473,411 Members | 1,949 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,411 software developers and data experts.

Is it possible to use python to unit test C++ code?

Is it possible to use python to unit test C++ code? If yes, is there
any example available?

Thank you.

Dec 21 '05 #1
5 11443

On 21 Dec 2005, at 09:33, sy*******@gmail.com wrote:
Is it possible to use python to unit test C++ code? If yes, is there
any example available?

Thank you.

--
http://mail.python.org/mailman/listinfo/python-list


You could use Python to unittest a Python module written in C++ I
suppose. I guess that would probably work. I suspect that you would
get better/more accurate/reliable results by writing your tests in C+
+ as well though.
Dec 21 '05 #2
sy*******@gmail.com wrote:
Is it possible to use python to unit test C++ code? If yes, is there
any example available?


If I had to use python to test C++ code, I'd use the Boost python
library: http://www.boost.org/libs/python/doc/ to expose my C++
classes, and write the unittests in python after importing the wrapped
C++ code.
Note, you did ask if it was possible. Is it advisable? That's another
question.

All the best,

Keir.

Dec 21 '05 #3

sylcheung> Is it possible to use python to unit test C++ code? If yes,
sylcheung> is there any example available?

Yes, it's quite possible. Some people even do it. ;-) As for examples, take
a look at Python's own test suite. Much of the code it contains actually
tests modules written in C, which is near enough to C++ for our purposes.
For example, consider that the math module is a thin wrapper around bits of
standard C89 math functions. The test_math.py script then exercises that
code.

So, you'll have to wrap your C++ library to make it available in Python
(check out SWIG and/or Boost and/or Python's Extending and Embedding
documentation), then write test cases. For that, look at the unittest and
doctest modules that come with Python as well as the third-party py.test
package.

Skip

Dec 21 '05 #4

samuel> Thanks. When I use python to unit test my c++ code. Do I need
samuel> only the .o file? or I need the .c/.h files of the c++ code? If
samuel> the input is .c/.h files, how can I compile it for unit testing
samuel> purposes?

Your wrapper module will need the header files from your C++ library and it
will by dynamically linked against the library's .so (or .dll).

Skip
Dec 22 '05 #5
I have used the Python version of this:

http://cxxtest.sourceforge.net/

unit testing framework successfully (but not heavily).

Hth,
Giles Brown

Dec 22 '05 #6

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
50
by: Edward K. Ream | last post by:
I would like to say a few (actually more than a few) words here about some recent discoveries I have made concerning the interaction of Leo and Python. If you don't want to hear an inventor enthuse...
27
by: Josh | last post by:
We have a program written in VB6 (over 100,000 lines of code and 230 UI screens) that we want to get out of VB and into a better language. The program is over 10 years old and has already been...
2
by: Pierre Rouleau | last post by:
Hi all, I have a consistent test case where os.popen3() hangs in Windows. The system hangs when retrieving the lines from the child process stdout. I know there were several reports related to...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 380 open (-36) / 3658 closed (+65) / 4038 total (+29) Bugs : 965 open ( -9) / 6555 closed (+35) / 7520 total (+26) RFE : 272 open...
9
by: jezonthenet | last post by:
I started using Python a couple of days ago - here are a few questions: * Doesn't the __main__() method automatically execute when I run my python program? * Only when I do an import of my...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
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...
0
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,...
0
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...
0
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...

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.