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
- Install Eclipse CDT from https://www.eclipse.org/cdt/
- In Eclipse go to Help -> Install New Software…
- Select default Eclipse Update site in the Work with field, for me its Kepler – http://download.eclipse.org/releases/kepler
- 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
- Download google test from https://code.google.com/p/googletest/
- Unpack google test somewhere on your computer.
- Create a google test build dir.
- 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
- Create a new C++ project in Eclipse using File -> New -> C++ Project
- Create a source folder to hold your tests by right clicking on your project and choosing New -> Source Folder
- 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.
- Go into properties for the test folder by right clicking on the folder and selecting properties
- Select C/C++ Build ->Settings
- Under GCC C++ Compiler -> Includes. Add <google test folder>/include and the folder where your project source files will be.
- Under GCC C++ Linker -> Libraries. Add the google test build folder and the libraries gtest and pthread
- If Eclipse still shows errors, you can try to rebuild your index.
Create a launch configuration
- Once you have written your first test, build your project, and go into the Run ->Run configurations… menu.
- Double click on C/C++ Unit to create a unit test configuration.
- In main tab select your project and the binary you just built.
- Go to C/C++ Testing tab and select the google tests runner
- 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!
Pingback: Setting up Eclipse CDT and Google Test for C development | Tear Driven Development