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
14
votes
7 answers

Android NDK with Google Test

I'm trying to use GoogleTest on Android Studio. According to what I understood, the latest version of NDK has the gtest included. I did not find a clear guide how to do it. I followed this document: So, I opened a new project, created jni folder and…
ShiraOzeri
  • 291
  • 4
  • 14
14
votes
1 answer

How to pretty-print QString with GoogleTest framework?

I am using the GoogleTest (GTest) framework in conjunction with a Qt5 application. Whenever a test fails using a QString argument, the framework tries to print all the involved values. However, it cannot automatically handle foreign types (Qt5's…
Philip Allgaier
  • 3,505
  • 2
  • 26
  • 53
14
votes
2 answers

Where can I find comprehensive documentation on Google Test?

A Google search yields the GitHub page for Google Test. I'm finding many links around the web to https://github.com/google/googletest, which now redirects to the GitHub page. The GitHub project has an overview and a readme.md, which mostly explains…
Linus Lindholm
  • 291
  • 1
  • 2
  • 10
14
votes
4 answers

Segmentation fault while running Google test

I am getting a segmentation fault when I try running gtest by mocking a method that accepts pointer to a object as the argument. I identified the mock method that is creating the trouble. class NvmControllerMockApp : NvmController_API { public: …
user3921737
  • 141
  • 1
  • 1
  • 5
14
votes
3 answers

Compare Eigen matrices in Google Test or Google Mock

I was wondering if there is a good way to test two Eigen matrices for approximate equality using Google Test, or Google Mock. Take the following test-case as a simplified example: I am multiplying two complex valued matrices A, and B, and expect a…
Lemming
  • 4,085
  • 3
  • 23
  • 36
14
votes
2 answers

how to use EXPECT_EQ for user defined type

I wanted to test a function which returns some user defined type value. I knew that I can test basic int, float, double etc with EXPECT_EQ, EXPECT_FLOAT_EQ etc but not for user defined type. any clue?
Amaresh Kumar
  • 586
  • 1
  • 8
  • 20
13
votes
2 answers

How to mock methods return object with deleted copy-ctor?

If an interface has a function to create an object with deleted copy-ctor, how to mock this function? Gmock seems to use the object's copy constructor internally. E.g. // The object with deleted copy-ctor and copy-assignment class TTest { public: …
Mine
  • 4,123
  • 1
  • 25
  • 46
13
votes
1 answer

How to run Parameterized Tests with fixture member values in Google Test (gtest)?

What I want to achieve is a Paramaterized Test TEST_P(MyFixtureClass, DoStuff), with which I can test different values. Though said values shouldn't be constants, like those typically passed to INSTANTIATE_TEST_CASE_P. Moreover, I would want to use…
Nikita
  • 609
  • 2
  • 7
  • 18
13
votes
1 answer

How can I tell GoogleMock to stop checking an expectation after the test finished?

I have two unit tests that share some state (unfortunately I can't change this since the point is to test the handling of this very state). TEST(MySuite, test1) { shared_ptr first(make_shared()); …
Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
13
votes
3 answers

Run tests in specific order

I've installed in Visual Studio 2013 the Google Test runner extension. Now I have a test project TestProject | |-InitializationTests.cpp |-RunningTests.cpp I want to run all test cases inside InitializationTests.cpp before tests inside…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
13
votes
6 answers

undefined reference to testing::internal::EqFailure in gtest

I am trying to do a test for a function using GoogleTest an now it is not finding anymore the EqFailure thing: /usr/include/gtest/gtest.h:1337: undefined reference to `testing::internal::EqFailure(char const*, char const*, testing::internal::String…
sop
  • 3,445
  • 8
  • 41
  • 84
13
votes
1 answer

C++ Mock/Test boost::asio::io_stream - based Asynch Handler

I've recently returned to C/C++ after years of C#. During those years I've found the value of Mocking and Unit testing. Finding resources for Mocks and Units tests in C# is trivial. WRT Mocking, not so much with C++. I would like some guidance on…
rbellamy
  • 5,683
  • 6
  • 38
  • 48
13
votes
2 answers

Create tests at run-time (google test)

I have a Parser that has to be tested. There are lots of test input files to this Parser. The expected behaviour of the Parser is tested by comparing output of the Parser with corresponding pregenerated files. Currently I'm processing YAML file in…
Egor Okhterov
  • 478
  • 2
  • 9
  • 34
13
votes
3 answers

How to add timeout to test when using Google Testing framework

I'm in need to test C++ code - and I've decided to use Google's testing framework. I need to make sure that a test doesn't hang due to a new bug. In the .NET testing framework it's possible to add [Timeout] on to of the test in order to make sure…
Dror Helper
  • 30,292
  • 15
  • 80
  • 129
13
votes
2 answers

How to make Google Test detect the number of threads on Linux?

When running the death tests written using Google Test framework the following warning is produced for each of the tests: [WARNING] .../gtest-death-test.cc:789:: Death tests use fork(), which is unsafe particularly in a threaded context. For this…
vitaut
  • 49,672
  • 25
  • 199
  • 336