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

Discussion in 'Python' started by sylcheung@gmail.com, Dec 21, 2005.

  1. Guest

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

    Thank you.
    , Dec 21, 2005
    #1
    1. Advertising

  2. On 21 Dec 2005, at 09:33, 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.
    Alex Stapleton, Dec 21, 2005
    #2
    1. Advertising

  3. keirr Guest

    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.
    keirr, Dec 21, 2005
    #3
  4. Guest

    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, 2005
    #4
  5. Guest

    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, 2005
    #5
  6. Giles Brown Guest

    Giles Brown, Dec 22, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Lundh
    Replies:
    0
    Views:
    851
    Fredrik Lundh
    Oct 30, 2006
  2. kathy
    Replies:
    0
    Views:
    1,291
    kathy
    Aug 2, 2011
  3. David Mitchell
    Replies:
    10
    Views:
    245
  4. James Wenton
    Replies:
    3
    Views:
    241
    Ryan Davis
    May 26, 2010
  5. timr
    Replies:
    2
    Views:
    154
Loading...

Share This Page