The Search For A Simple C++ Unit Tester : GoogleTest

For a full list of my adventures in search of a c++ unit tester, return to the main page here. This section will focus on one candidate: GoogleTest.

GoogleTest

Documentation: GoogleTest

Installation

Downloaded the source and followed the instructions in the README file. They were a little confusing, but worked perfectly.

Run An Example

After reading the documentation, I felt able to write my own test file from scratch. However, compiling the test turned out to be an awful ordeal. Perhaps I just didn’t find the right documentation page, but it took¬†forever to figure out exactly what I needed. Eventually, I realized I needed the gtest_main.a library, which is made using the make/Makefile or by the following commands:

g++ -I../include -I.. -g -Wall -Wextra -c ../src/gtest-all.cc
g++ -I../include -I.. -g -Wall -Wextra -c ../src/gtest_main.cc
ar rv gtest_main.a gtest-all.o gtest_main.o

From there, I could make my own test files using:

~/gtest-1.6.0/myclass% make
g++ -c -g -Wall -Wextra myclass.cpp
g++ -I../include -g -Wall -Wextra -c mytester.cpp
g++ -I../include -g -Wall -Wextra -lpthread myclass.o mytest.o gtest_main.a -o googletest

Assessment

Pros
  • Great documentation!
  • Helper functions allowed within a test (although you would have to use messages to create a useful backtrace)
  • Lots of useful functions (ASSERT vs EXPECT, cstring comparisons, neq)
  • Output is color coded!! (at least, in my terminal window)
Cons
  • Makefile gets a bit complicated
  • Output presents a lot of information. Possibly more than needed

Rating: 9

Advertisements
This entry was posted in C++. Bookmark the permalink.

One Response to The Search For A Simple C++ Unit Tester : GoogleTest

  1. Pingback: The Search For A Simple C++ Unit Tester | denvercoder9

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s