Testing C++ code using GoogleTest on Eclipse (MinGW ToolChain)

I’ve been trying to test a very simple piece of code using googleTest, and it took me 3 days to get it done. The main issue was for me to be able to set the environment. This post is on how to set the environment, followed by the list of mistakes I’d done.
Basically what I wanted to do was to keep my project separate from my tests, so that the tests would go into a separate project.

  1. Go to GoogleTest on GitHub where you can find documentation, code, and a couple of examples on how to use it. You can clone it into your local or download it.
  2. Open Eclipse. Let’s say we are testing a project called base_project, now you need to create another project called unit_test maybe.
  3. In your test project you need below to be created.One folder to hold googletest libraries, let’s call it googleTestLib, and a folder to hold your unit tests, let’s call it tests
  4. Using your command prompt, cd into where you have googleTest stored. In this path \googletest\googletest\scripts, there should be a file called fuse_gtest_files.py. Run the script, as usual, using .\ fuse_gtest_files.py {the project location}\ googleTestLib . Refreshing your unit_test project, googleTestLib should now have a folder called gtest with a gtest.h and gtest-all.cc file inside it.5- Right click on googleTestLib folder, go to resource configuration, and exclude it from “release”
  5. Right click on googleTestLib folder, go to properties, under C/C++ Build click on settings, find the include link under GCC C++ Compiler and click on it. Now add the folder (googleTestLib) as an include path
    Continue reading “Testing C++ code using GoogleTest on Eclipse (MinGW ToolChain)”