Questions tagged [googletest]

Google's C++ testing framework based on xUnit that runs on multiple platforms.

GoogleTest is an open source unit testing framework developed by Google. It also supports unit testing of C code.

GTest (as it is commonly known) supports various platforms including Linux, OS X, Windows and Symbian. It provides basic unit testing features in the xUnit model in the form ASSERT_EQ() or EXPECT_EQ(), with automatic test registration. It also provides advanced features such as death tests, shuffling and sharding of tests, and Hudson/Jenkins-compatible XML output.

GTest integrates well with gmock, a C++ mocking framework.

There are three GTest related open source projects which can enhance the GTest user experience:

  1. Google Test UI - provides a GUI for running gtest binary and displaying the results.
  2. GTest TAP listener - Event listener for GTest based on TAP, for test result output.
  3. gtpp - Google Test Pretty Printer, offering shorter and clearer console test output
2773 questions
16
votes
3 answers

CMake: How to specify directory where ctest should look for executables?

I wanted to integrate ctest to a c++/c project. I use google tests to write unit tests. Relevant part of my CMakeLists.txt looks like this: ... ####### CREATING EXE ####### add_executable(test_exe main.cpp test.cpp) target_link_libraries(test_exe…
ysfaran
  • 5,189
  • 3
  • 21
  • 51
16
votes
1 answer

Google mock ByRef method

I have a class that takes a boolean as a reference parameter and returns an integer: class Foo { public: Bar my_bar; virtual int myMethod(bool &my_boolean) = 0; } /*...*/ int Foo::myMethod(bool &my_boolean){ if (my_bar == NULL){ …
Rodrigo Vasconcelos
  • 1,270
  • 2
  • 14
  • 26
16
votes
1 answer

Eclipse (CDT) plugin for running tests and browsing report

Google's answers (hear! hear!) and Eclipse Market Place search results on this topic simply drive me crazy! And apparently the proposed SO answers aren't really helpful either. I'm looking for an Eclipse plugin, that allows me to browse a JUnit…
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
15
votes
3 answers

linking error when building Google test on mac (commandline)

I am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating ld: warning: in /usr/local/lib/libgtest.dylib, file was built for unsupported file format which is not the architecture being…
gnash117
  • 1,025
  • 1
  • 13
  • 24
15
votes
6 answers

Configure gtest to show failed test only in console

Is there an option to show only failed tests? I had to switch to use Guitar to achieve this, but I miss command line tool.
Yuan
  • 2,690
  • 4
  • 26
  • 38
15
votes
1 answer

Building tests with CMake while not using CTest

Here is what I want to do: Typing make all will build my library and the docs for it. Typing make test will build my lib (if necessary), gtest and then my tests Typing make check runs make test if needed and then runs the executable Right now I've…
Nicklas A.
  • 6,501
  • 7
  • 40
  • 65
15
votes
2 answers

How to check if the test failed in Google Test TearDown()?

At the end of every "file based integration" test, I want to clear a temp folder of associated files. If the test fails, I want to leave the files there, so I can review the unexpected output. Is there a way in the Google Test TearDown to check if…
deworde
  • 2,679
  • 5
  • 32
  • 60
15
votes
2 answers

Google Test can't find user provided equality operator

I'm using Google Test v1.7 I've created a custom operator == which ASSERT_EQ can't find, but which can be found if used directly. Here's the code #include #include #include "gtest/gtest.h" template< typename T> struct bar { T b;…
Diab Jerius
  • 2,310
  • 13
  • 18
15
votes
3 answers

Can ctest display googletest console colors

I am building and running unit tests built with googletest inside a cmake project with ctest enabled I run the tests with "ctest -VV" but the test output does not color the "red" and "green" [ RUN ] [ OK ] [ PASSSED ] Does anyone know…
MyDeveloperDay
  • 2,485
  • 1
  • 17
  • 20
15
votes
1 answer

Why the compiler does not recognize Google Mock wildcard?

When I try to use: ON_CALL(mock, foo(_)) Compilation error is thrown: Error 1 error C2065: '_' : undeclared identifier I am using visual studio 2012.
User234
  • 237
  • 1
  • 2
  • 9
15
votes
5 answers

find external test file for unit test by relative path c++ cmake guest

What would be the proper way to access an external test file for the unit test of a c++ project? I am using CMake and Gtest. This is a sample of the directory structure. Project -src -test (unit tests here) -test-data (data file…
Teancum
  • 245
  • 1
  • 2
  • 9
15
votes
2 answers

GoogleTest: Accessing the Environment from a Test

I'm trying out gtest for C++ (Google's unit testing framework), and I've created a ::testing::Environment subclass to initialize and keep track of some things that I need for most of my tests (and don't want to setup more than once). My question is:…
jco
  • 1,335
  • 3
  • 17
  • 29
15
votes
2 answers

Compare containers with GoogleTest

I'm trying to get a working googletest test that compares two vectors. For this I'm using google mock with its matchers but I get a C3861 error saying "ContainerEq identifier not found" and also C2512 saying "testing::AssertionResult has not a…
Stefano
  • 3,213
  • 9
  • 60
  • 101
14
votes
2 answers

What's the way to access argc and argv inside of a test case in Google Test framework?

I’m using Google Test to test my C++ project. Some cases, however, require access to argc and argv to load the required data. In the main() method, when initializing, argc and argv are passed to the constructor of…
Nils
  • 13,319
  • 19
  • 86
  • 108
14
votes
7 answers

How to compile googletest on windows using mingw with msys?

My need is simple. I have to compile and use googletest on windows using MinGW with msys. Has anyone some experience doing this? Thanks for answers.
Rusty Horse
  • 2,388
  • 7
  • 26
  • 38