14

I'm looking for a test framework for C++ in Eclipse CDT. Ideally it should have similar functionalities to those offered by JUnit.

I tried CUTE. It is good but I cannot seem to create unit tests within the project I'm currently working on. Neither can I create a separate unit test project to test my current project, because my current project is a C++ hello world application, but CUTE only allows testing project for a C++ library.

Any idea of other test frameworks I may count on, and is there any tutorial available? Thanks.

Shuo
  • 4,749
  • 9
  • 45
  • 63

6 Answers6

9

I use Google Test Framework and Google Mock Framework with Eclipse CDT C/C++ Tests Runner plugin. This plugin also works with qt tests and boost tests. Look and feel like junit in java eclipse :)

Google test framework is very well described here: http://code.google.com/p/googletest/

Eclipse CDT C/C++ Tests Runner plugin: https://github.com/xgsa/cdt-tests-runner/wiki/Tutorial

You can use it by creating new project for test or directly in current project by creating separate build and run action for test runner. I have 2 folders in my project, Source and Tests, Tests folder is exclude from normal build, so I can run test and build application using one project.

dikamilo
  • 617
  • 7
  • 7
  • 3
    C++ test runner is now part of eclipse CDT - http://stackoverflow.com/questions/16741400/eclipse-cdt-plugin-for-running-tests-and-browsing-report – L.R. Nov 22 '13 at 19:55
4

The problem you describe with CUTE is that you need to find a way to split up your application so you move the functionality you want to test to a library. Every test framework will put this requirement on your project structure.

Try GoogleTest or Boost.Test.

GoogleTest does not have a plugin for Eclipse.

see this issue: http://code.google.com/p/googletest/issues/detail?id=40

Cppunit is abandonware in the sense that it is not actively being maintained anymore.

Eddy Pronk
  • 6,527
  • 5
  • 33
  • 57
  • Does it make cppunit invaluable though? :) – supertopi Nov 06 '11 at 22:40
  • Does GoogleTest have Eclipse plugin? – Shuo Nov 07 '11 at 05:48
  • 1
    @Topi Ojala: historically it has great value and a lot of projects are still using it. If you start from scratch I'd recommend to pick one of the more recent once, since they made a big step forward. CppUnit was great, but it doesn't seem to evolve. – Eddy Pronk Nov 07 '11 at 07:00
  • The README file that comes with GTest's installation package is hard to follow. Do you happen to know any useful tutorials that might help me to setup GTest? Thanks. – Shuo Nov 08 '11 at 05:18
  • 2
    Where in the README did you get stuck? – Eddy Pronk Nov 08 '11 at 06:07
  • g++ -I${GTEST_DIR}/include path/to/your_test.cc libgtest.a -o your_test – Shuo Nov 08 '11 at 06:09
  • I got " undefined reference to `pthread_setspecific' collect2: ld returned 1 exit status" – Shuo Nov 08 '11 at 06:09
  • Give g++ the option -lpthread or -pthread to link with the POSIX thread library. – Eddy Pronk Nov 08 '11 at 06:17
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4794/discussion-between-eddy-pronk-and-shuo) – Eddy Pronk Nov 08 '11 at 06:22
1

I found this posting in my quest for a simple CppUnit integration with Eclipse CDT... So for everyone like me who is seeking a simple CppUnit integration with Eclipse CDT:

I have created an Eclipse plugin to support vanilla CppUnit XML Test Reports with the official Eclipse CDT C/C++ Unit Testing Support plugin.

I have made it available at: https://sourceforge.net/projects/eclipsecppunit/

harrisjmr
  • 21
  • 2
1

Well there is https://github.com/xgsa/cdt-tests-runner/wiki/Tutorial for eclipse with google test

Kastor
  • 478
  • 5
  • 12
1

CppUTest is a C/C++ based unit xUnit test framework for unit testing: http://cpputest.github.io/

It is still actively maintained, and there's CppUTest Eclipse Plugin "made to make unit testing easier to work with CppUTest & Eclipse", and acts like JUnit plugin.

You can also have a look at CppUTest Test Runner for Eclipse Juno or above

raphaelh
  • 735
  • 6
  • 8
1

Have you tried cppunit?

http://sourceforge.net/projects/cppunit/

I don't use eclipse, but they seem to have a page explaining how to integrate both:

http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=CppUnitWithEclipse

There are many tutorials if you search on Google.

Cheers

leo
  • 1,117
  • 1
  • 8
  • 18