How to get started with Google Test in Eclipse CDT on Linux.

Setting up your development tools is an important first step in TDD, and its not always as easy as one could think.

I found that setting up my C++ development environment a little bit troublesome, and there wasn’t that many good how-to:s out there..

Here is How i get up and running with Eclipse CDT and google test.

Install Eclipse with Unit test support

  1. Install Eclipse CDT from https://www.eclipse.org/cdt/
  2. In Eclipse go to  Help -> Install New Software…
  3. Select default Eclipse Update site in the Work with field, for me its  Kepler – http://download.eclipse.org/releases/kepler
  4. Install package C/C++ Unit Testing Support under Programming Languages, you will need to restart your IDE once the installation is done.

Get and compile Google Test

  1. Download google test from https://code.google.com/p/googletest/
  2. Unpack google test somewhere on your computer.
  3. Create a google test build dir.
  4. cd into your build directory and type “cmake <google test directory>”  and “make” to build google test.

Configure a C++ Project to use Google Test in the same project

  1. Create a new C++ project in Eclipse using File -> New -> C++ Project
  2. Create a source folder to hold your tests by right clicking on your project and choosing New -> Source Folder
  3. It is usually a good idea to not include your tests in your release build so right click on your test folder and select ->Resource Configurations -> Exclude from Build… and exclude the folder from Release.
  4. Go into properties for the test folder by right clicking on the folder and selecting properties
  5. Select C/C++ Build ->Settings
  6. Under GCC C++ Compiler -> Includes. Add <google test folder>/include and the folder where your project source files will be.
  7. Under GCC C++ Linker -> Libraries. Add the google test build folder and the libraries gtest and pthread
  8. If Eclipse still shows errors, you can try to rebuild your index.

Create a launch configuration

  1. Once you have written your first test, build your project, and go into the Run ->Run configurations… menu.
  2. Double click on C/C++ Unit to create a unit test configuration.
  3. In main tab select your project and the binary you just built.
  4. Go to C/C++ Testing tab and select the google tests runner
  5. Click run and your tests should now run

Once everything is set up using eclipse and google test will be quite easy and convenient to work with!

One thought on “How to get started with Google Test in Eclipse CDT on Linux.

  1. Pingback: Setting up Eclipse CDT and Google Test for C development | Tear Driven Development

Leave a comment