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
41
votes
4 answers

What is the difference between gtest and gmock?

I'm trying to understand the purpose of google-mock, Google's C++ mocking framework. I have already worked with gtest earlier, but still I can't understand what gmock is. Why do we need it? gtest is used for unit testing. What do we need gmock for…
Rasmi Ranjan Nayak
  • 11,510
  • 29
  • 82
  • 122
40
votes
4 answers

Error with EXPECT_EQ for sum of double or float

I am unable to understand why the test case failed in case of summing double numbers or floats. It works very finely for the integer data type. //the method in simple_method.h double sum ( double a, double b) { double res = a+b; return…
suma
  • 673
  • 3
  • 7
  • 13
39
votes
3 answers

What's the difference between gtest.lib and gtest_main.lib?

Google's C++ Test Framework has two output libraries: one is gtest.lib and the other one is gtest_main.lib. According to Nik Reiman's answer on how to setup gtest with Visual Studio, we should link to gtest_main.lib but I'm linking to gtest.lib and…
Kiril
  • 39,672
  • 31
  • 167
  • 226
38
votes
1 answer

How to pass parameters to the gtest

How can I pass parameter to my test suites? gtest --number-of-input=5 I have the following main gtest code. And --number-of-input=5 should be passed to InitGoogleTest(). #include #include int main(int argc, char **argv)…
prosseek
  • 182,215
  • 215
  • 566
  • 871
37
votes
4 answers

google mock : how can I " EXPECT " that no method will be called on a mock

I want to test that in case of some fail no method will be called on a mock object, using google mock. So the code would be something like: auto mockObj = new MockObj; EXPECT_NO_METHOD_CALL(mockObj); // this is what I'm looking for auto mainObj =…
angela d
  • 725
  • 1
  • 8
  • 12
37
votes
1 answer

Google test: Can I query the name of the test fixture?

I want to use google test to write a class that derives from ::testing::Test and adds functionalities to it using mostly the constructor, or SetUp and TearDown(). Looks like SetUp/TearDown is the way to go so far. My question is: Let's say we have a…
nirvanaswap
  • 859
  • 2
  • 11
  • 21
37
votes
4 answers

CMake cannot find GoogleTest required library in Ubuntu

Similar issue here. This is my CMakeLists.txt: cmake_minimum_required(VERSION 2.6) # Locate GTest find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS}) # Add test cpp file add_executable(foo foo.cpp) # Link test executable…
Erich
  • 371
  • 1
  • 3
  • 5
37
votes
1 answer

Why is GoogleMock leaking my shared_ptr?

I use GoogleMock/GoogleTest for testing, and I'm seeing some strange behavior when a matcher has a shared_ptr to a mock as a parameter, and EXPECT is called on the same shared_ptr. The offending piece of code: #include #include…
bruno nery
  • 2,022
  • 2
  • 20
  • 31
36
votes
6 answers

Separate test cases across multiple files in google test

I'm new in google test C++ framework. It's quite easy to use but I'm wondering how to separate the cases into multiple test files. What is the best way? Include the .cpp files directly is an option. Using a header seems that does nothing... Any help…
Killrazor
  • 6,856
  • 15
  • 53
  • 69
36
votes
5 answers

using googletest in eclipse: how?

I've downloaded google test, but now I've no idea on how to link it to my project in eclipse. Should I add it as a source folder? Should include it as g++ included library? And how can I run test then?
user478310
  • 361
  • 1
  • 3
  • 4
36
votes
5 answers

error during making GTest

I was trying to set up GTest environment on my Ubuntu machine. but while making the GTest to get the library, i get the following error... som@som-VPCEH25EN:~/Workspace/CPP/gtest-1.6.0/make$ make g++ -I../include -g -Wall -Wextra -lpthread sample1.o…
somenath mukhopadhyay
  • 1,548
  • 1
  • 16
  • 18
34
votes
3 answers

google mock - can I call EXPECT_CALL multiple times on same mock object?

If I call EXPECT_CALL twice on the same mock object in the same TEST_F . . . what happens? Are the expectations appended to the mock object or does the second call erase the effects of the first call? I found The After Clause which appears to imply…
Bob
  • 4,576
  • 7
  • 39
  • 107
34
votes
9 answers

How to install GTest on Mac OS X with homebrew?

I'm trying to install gtest with my packet manager Home Brew but there is no repository for it. I tried to download gtest from code.google but I can't understand how to install it, because cmake and make don't solve the problem.
a-rukin
  • 363
  • 1
  • 3
  • 6
33
votes
4 answers

Generate Google C++ Unit Test XML Report

I am new to using Google test framework for unit testing and am intending to generate an XML report of the tests or the command output as a report (I could just print it obviously). I have read up on Generate XML Report , but haven't been able to…
Neophile
  • 5,660
  • 14
  • 61
  • 107
33
votes
2 answers

What are Google Test, Death Tests

I saw the documentation of that feature is seem pretty major since it's in Google Test overview features and detailed in: https://github.com/google/googletest/blob/master/docs/advanced.md#death-tests They look like standard assert() but they're part…
Wernight
  • 36,122
  • 25
  • 118
  • 131