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
335
votes
9 answers

Comparison of C++ unit test frameworks

I know there are already a few questions regarding recommendations for C++ unit test frameworks, but all the answers did not help as they just recommend one of the frameworks but do not provide any information about a (feature) comparison. I think…
housemaister
  • 3,918
  • 3
  • 19
  • 13
186
votes
3 answers

How to run specific test cases in GoogleTest

I am trying to write a function/method for my project, which will ask to user which all test cases are you going to run? It looks like below..., Test_Cases_1 |_TestNo1 |_TestNo2....so on Test_Cases_2 |_TestNo1 …
Rasmi Ranjan Nayak
  • 11,510
  • 29
  • 82
  • 122
178
votes
8 answers

GoogleTest: How to skip a test?

Using Google Test 1.6 (Windows 7, Visual Studio C++). How can I turn off a given test? (aka how can I prevent a test from running). Is there anything I can do besides commenting out the whole test?
User
  • 62,498
  • 72
  • 186
  • 247
158
votes
12 answers

How to start working with GTest and CMake

I have recently been sold on using CMake for compiling my C++ projects, and would now like to start writing some unit tests for my code. I have decided to use the Google Test utility to help with this, but require some help in getting started. All…
Chris
  • 8,030
  • 4
  • 37
  • 56
138
votes
4 answers

C++ project organisation (with gtest, cmake and doxygen)

I am new to programming in general so I decided that I would start by making a simple vector class in C++. However I would like to get in to good habits from the start rather than trying to modify my workflow later on. I currently have only two…
rozzy
  • 2,828
  • 6
  • 25
  • 35
130
votes
2 answers

How to specify multiple exclusion filters in --gtest_filter?

The question is about google-test framework. I want to run all tests excluding some according to multiple exclusion filters, like: --gtest_filter=-ABC.*:-BCD.*
abyss.7
  • 13,882
  • 11
  • 56
  • 100
123
votes
6 answers

How to send custom message in Google C++ Testing Framework?

I use Google C++ Testing Framework for unit testing of my code. I use Eclipse CDT with C++ Unit testing module for output analysis. Previously I used CppUnit it has macros family CPPUNIT*_MESSAGE that could be called like this:…
Yuriy Petrovskiy
  • 7,888
  • 10
  • 30
  • 34
116
votes
10 answers

Comparison of arrays in google test?

I am looking to compare two arrays in google test. In UnitTest++ this is done through CHECK_ARRAY_EQUAL. How do you do it in google test?
Tobias Furuholm
  • 4,727
  • 4
  • 30
  • 39
103
votes
14 answers

How to set up googleTest as a shared library on Linux

Debian does not provide any precompiled packages for gTest anymore. They suggest you integrate the framework into your project's makefile. But I want to keep my makefile clean. How do I set up gTest like the former versions (<1.6.0), so that I can…
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
98
votes
5 answers

Is Google Test OK for testing C code?

So I've come to like and enjoy using Google Test for a C++ project I'm involved in. I'm just bringing up a new project that will be straight C (a library) and so far can't see any reason why not to continuing using Google Test, even though its a…
Jason
  • 2,233
  • 3
  • 24
  • 27
84
votes
6 answers

How to set up Google C++ Testing Framework (gtest) with Visual Studio 2005

It is not documented on the web site and people seem to be having problems setting up the framework. Can someone please show a step-by-step introduction for a sample project setup?
knaser
  • 1,421
  • 7
  • 19
  • 16
80
votes
1 answer

What is the best way of testing private methods with GoogleTest?

I would like to test some private methods using GoogleTest. class Foo { private: int bar(...) } GoogleTest allows a couple of ways of doing this. OPTION 1 With FRIEND_TEST: class Foo { private: FRIEND_TEST(Foo, barReturnsZero); int…
Carlos Perez-Lopez
  • 951
  • 1
  • 7
  • 7
78
votes
14 answers

Test a specific exception type is thrown AND the exception has the right properties

I want to test that MyException is thrown in a certain case. EXPECT_THROW is good here. But I also want to check the exception has a specific state e.g e.msg() == "Cucumber overflow". How is this best implemented in GTest?
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
74
votes
3 answers

GoogleTest vs CppUnit: The facts

In the process of setting our C++ unit testing framework for the next years we shortlisted GoogleTest and CppUnit. I have some experience with both and my heavy preference is GoogleTest. Anyways to convince my boss I need some facts so I did some…
EstuansInterius
  • 849
  • 1
  • 7
  • 5
74
votes
7 answers

How to capture stdout/stderr with googletest?

Is it possible to capture the stdout and stderr when using the googletest framework? For example, I would like to call a function that writes errors to the console (stderr). Now, when calling the function in the tests, I want to assert that no…
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
1
2 3
99 100