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
73
votes
6 answers

Printing additional output in Google Test

I'm using the googletest C++ testing framework. Normally the textual output of running a test looks like this: [ RUN ] MyTest.Fuzz [ OK ] MyTest.Fuzz (1867 ms) I would like to output some additional data in the same format, for…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
72
votes
3 answers

Using ASSERT and EXPECT in GoogleTest

While ASSERT_* macros cause termination of test case, EXPECT_* macros continue its evaluation. I would like to know which is the criteria to decide whether to use one or the other.
martjno
  • 4,589
  • 5
  • 34
  • 31
60
votes
2 answers

What is the difference between TEST, TEST_F and TEST_P?

I have researched a lot about gtest/gmock but none of them gave me the right answer. I'm new to C++ so any help would be really appreciated.
Nguyễn Đức Tâm
  • 1,017
  • 2
  • 10
  • 24
58
votes
4 answers

How to make google-test classes friends with my classes?

I heard there is a possibility to enable google-test TestCase classes friends to my classes, thus enabling tests to access my private/protected members. How to accomplish that?
pajton
  • 15,828
  • 8
  • 54
  • 65
57
votes
6 answers

CMake + GoogleTest

I just downloaded googletest, generated its makefile with CMake and built it. Now, I need to use it in my testing project. With CMake, I have been advised not pointing to gtest libraries directly (using include _directories or link_directories) but…
Korchkidu
  • 4,908
  • 8
  • 49
  • 69
55
votes
4 answers

Google Test in Visual Studio 2012

I am trying to get started with unit testing. I downloaded the latest build of gtest, and extracted it to A:\gtest As the instructions specified, I opened gtest.sln. Visual studio only allows me to open the sln if I agree to update it. Then when I…
user1599559
54
votes
1 answer

SetUp vs Constructor in Test Fixture

Why does a test fixture have a SetUp method in Google Test? Isn't the Constructor effectively the same thing? Likewise for the TearDown method. Calls to both SetUp and the Constructor, as well as TearDown and the Destructor, are consistent with the…
Baz
  • 12,713
  • 38
  • 145
  • 268
51
votes
11 answers

What unit-testing framework should I use for Qt?

I am just starting up a new project that needs some cross-platform GUI, and we have chosen Qt as the GUI-framework. We need a unit-testing framework, too. Until about a year ago we used an in-house developed unit-testing framework for C++-projects,…
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
50
votes
3 answers

google-test: code coverage

Is it possible to get code coverage done by tests using google test framework?
gruszczy
  • 40,948
  • 31
  • 128
  • 181
49
votes
2 answers

How to catch an assert with Google test?

I'm programming some unit test with the Google test framework. But I want to check whether some asserts are well placed and are useful. Is there a way to catch an assert in Google test? Example code under test: int factorial(int n){ assert(n >=…
Killrazor
  • 6,856
  • 15
  • 53
  • 69
48
votes
3 answers

Boost Test Vs Google Test Framework

I am new to Unit Testing world, basically I am c++ developer working on a large product for almost 3 years, and now I've decided to perform automated unit testing of my code. For this I do lot of research on the internet and came across many tools…
Jame
  • 21,150
  • 37
  • 80
  • 107
46
votes
3 answers

Setup Google test in CLion

I have been sitting online for hours already trying to setup Google test on Clion in Linux but have not been able to find anything. Can someone guide me with setting this up please?
user2955610
  • 815
  • 2
  • 9
  • 15
44
votes
1 answer

Google Test: Is there a way to combine a test which is both type parameterized and value parameterized?

I know how to develop a type-parameterized test and value-parameterized test separately. What I am trying to figure out is if it's possible to combine both. In other words, create a generic test which takes any type and range of values for that…
linux fanatic
  • 551
  • 1
  • 6
  • 8
43
votes
2 answers

How to build some project configurations with msbuild

The gtest's msvc directory has the gtest project file, and opening it with Visual Studio enables me to select the build out of 8 configurations(gtest/gtest_main/gtest_prod_test/gtest_unittest x release/debug) with Batch Build. How can I do the same…
prosseek
  • 182,215
  • 215
  • 566
  • 871
42
votes
10 answers

SEH exception with code 0xc0000005 thrown in the test body

I am writing a test using GoogleTest for the following class and I am getting the above error. class Base { // Other Functions; CSig objSig[50]; } The Class CSig is as follows: class CSig { //... constructor, destructor(empty) and some…
chintan s
  • 6,170
  • 16
  • 53
  • 86