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
18
votes
3 answers

Google Test - Using "SetUpTestSuite" doesn't seem to work

I'm trying to write a test suite that performs a test-suite level "Set Up" operation. I attempted to write a simple program first to try and get it working but I am not having any luck getting the "SetUpTestSuite" method to be called. #include…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
18
votes
1 answer

Why does google test sample put tests in an anonymous namespace?

This is NOT a duplicate of Superiority of unnamed namespace over static? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static! I am asking, why are google tests placed inside…
Daniel Goldfarb
  • 6,937
  • 5
  • 29
  • 61
18
votes
2 answers

How to test c++ template class with multiple template parameters using gtest?

I want to test a template class with gtest. I read about TYPED_TESTs in gtest manual and looked at the official example (samples\sample6_unittest.cc) they reference. This template from the example has only one template parameter. But, my code has…
thinkerou
  • 1,781
  • 5
  • 17
  • 28
18
votes
2 answers

GoogleTest PrintTo not getting called for a class

I'm having a rather strange problem telling googletest to print a certain class the way I want using PrintTo. The class is a very simple 2D point, it is in a namespace and the PrintTo function is in the same namespace. In fact, I have a derived…
MikMik
  • 3,426
  • 2
  • 23
  • 41
18
votes
1 answer

Mocking Parametrized Constructor using Gmock

I have class to be mocked but it does not have a default constructor. I cannot change the source code, so is there any way to mock a parametrized constructor using Gmock
Daemon
  • 1,575
  • 1
  • 17
  • 37
18
votes
4 answers

How to make GTest build /MDd (instead of /MTd) by default, using CMake?

I am trying to integrate GTest with CMake as seamlessly as possible. But the default build type for my test projects are /MDd and GTest defaults to /MTd. I am manually changing GTest project properties to emit debug DLL. But every time I make…
Hindol
  • 2,924
  • 2
  • 28
  • 41
17
votes
4 answers

Benchmarking with googletest?

Background (skip to Question below if not interested) I have a simulator that runs through three states: Single threaded startup (I/O ok) Multi-threaded in-memory CPU-bound simulation stage (I/O not ok) Post-simulation, post-join single threaded…
kfmfe04
  • 14,936
  • 14
  • 74
  • 140
17
votes
1 answer

Using google tests with CMake/Ctest with the new command gtest_discover_tests

I am trying to use googletest with CMake/Ctest. I have several sources files for my tests (each one containing many TEST/TEST_F/... commands) which are located in several directories. I want that the tests related to a given source are executed in…
janou195
  • 1,175
  • 2
  • 10
  • 25
17
votes
2 answers

How to signal to gtest that a test wants to skip itself

I have a set of typed test cases in google test. However, some of these test cases are simply not applicable for a specific type parameter. Consider this example typed test case: TYPED_TEST_P(TheTest, ATest){ …
gexicide
  • 38,535
  • 21
  • 92
  • 152
17
votes
2 answers

GoogleTest 1.6 with Cygwin 1.7 compile error: 'fileno' was not declared in this scope

GoogleTest 1.6 with Cygwin 1.7: 'fileno' was not declared in this scope Error message when building a simple test on Factorial() function in Eclipse CDT: Invoking: Cygwin C++ Compiler g++ -std=c++0x -DGTEST_OS_CYGWIN=1…
Bill Clinton
  • 193
  • 1
  • 5
17
votes
1 answer

Uninteresting mock function call bla() && Expected: to be called at least once bla()?

I've written a small test with a mocked class. When I run it, first I get the warning that an uninteresting mock function was called and then the test fails because the expectation is not met, which is that the mocked function is called at least…
emmerich
  • 512
  • 1
  • 5
  • 14
17
votes
2 answers

No tests found when using gtest with cmake/ctest

I have a project with the following structure: linalg ├── build ├── CMakeLists.txt ├── docs │   └── Doxyfile ├── include │   └── linalg │   └── vector3.hpp ├── src │   ├── CMakeLists.txt │   └── linalg │   └── vector3.cpp └── test ├──…
rozzy
  • 2,828
  • 6
  • 25
  • 35
17
votes
2 answers

How to use google test for C++ to run through combinations of data

I have a unit test that I need to run for 200 possible combinations of data. (The production implementation has the data to be tested in configuration files. I know how to mock these values). I prefer nit writing separate test case for each…
Karthick S
  • 3,204
  • 6
  • 36
  • 52
16
votes
3 answers

Googletest does not accept temporary object in EXPECT_THROW

I have a class that has no default constructor, but the constructor may throw. I was wanting to have a test like: EXPECT_THROW(MyClass(param), std::runtime_error); But the compiler, g++, complains that there is no default constructor for MyClass.…
thumper
  • 423
  • 1
  • 4
  • 11
16
votes
3 answers

Pass argument from ctest to gtest

I am using gtest to write unit tests for my application. I also have ctest that runs all executables added by add_test CMake command. Is it possible to pass gtest variables through ctest when test execution starts? I would like to for example…
drodil
  • 2,292
  • 1
  • 22
  • 37