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
1
vote
1 answer

gtest - composing EXPECT_NO_THROW and EXPECT_EQ

I need to use EXPECT_NO_THROW and EXPECT_EQ for the function which returns some value. Here is my solution: int value = 0; EXPECT_NO_THROW(value = GetValue()); EXPECT_EQ(value, 99); Is there any other way to compose EXPECT_NO_THROW and EXPECT_EQ ?
Irbis
  • 11,537
  • 6
  • 39
  • 68
1
vote
1 answer

Run gtest util it fails

Is there a way to run the google test in Visual Studio until it fails?? I have this TEST_F(PersistentStorageTestFixture, test_PSF_U13) test fails but it is intermittent. I need to run it again and again until it fails, any thoughts?
Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76
1
vote
1 answer

Test project has problems accessing a private static method, even though I never directly call it

I am trying to add some missing skills to my repertoire, one of which is setting up a proper parallel test project. I have a simple setup in one project (EffCPP) to experiment with some C++ concepts and I am trying to set up a Google Test project…
Vidrohi
  • 112
  • 10
1
vote
0 answers

Setting up gmock with google test

Could someone please help me compile the google test framework using google mock? Currently, I have this cmake file: cmake_minimum_required(VERSION 3.2) if (CMAKE_VERSION VERSION_LESS 2.8.11) include_directories(BEFORE SYSTEM …
Razvan
  • 151
  • 4
  • 14
1
vote
1 answer

Passing a mock through a factory in C++

I am using GoogleTest to create a unit test in my project. I want to mock a specific object implementing the following interface : class IMockableObject { public: IMockable(); IMockable(const IMockable &other); // copy constructor virtual…
oOnez
  • 887
  • 2
  • 11
  • 23
1
vote
0 answers

C++ Cmake build with cotire and gtest - error with float.h

I have a cmake build that uses gtest - everything works as expected. When I add cotire in I get the error: error: use of undeclared identifier 'DBL_MAX' Anywhere #import is used It seems to me that some setting is being fubar'd by adding…
accordionfolder
  • 573
  • 4
  • 17
1
vote
1 answer

Race condition segfault when using gtest EXPECT_CALL while another expectation is exercising the same method

I've encountered a race condition segfault when using GTest with mocks and multithreading. I'm using GTest 1.8 on CentOS 6.9, G++ 6.3.1. It is possible to trigger a segfault by calling EXPECT_CALL on a mock with a given method, whilst another thread…
Obiphil
  • 361
  • 1
  • 6
  • 17
1
vote
0 answers

Could not compile simple Google Test example

I've got troubles with Google Test. On Ubuntu 17.04 I've build Google Test using commands: sudo aptitude install libgtest-dev cd /usr/src/gtest sudo cmake -DBUILD_SHARED_LIBS=ON . sudo make sudo mv libgtest* /usr/lib Then I try to compile very…
Dmitriy Vinokurov
  • 365
  • 1
  • 6
  • 28
1
vote
0 answers

unresolved symbols for the constructor and other member functions while writing unit test using google test framework

There is library say myLib in my myLib.vcproj It has class namespace mylibtuils{ struct DefaultHander: IHandler { DefaultHander():_mV1(0),_mV2(1), _mv3(4){ } ~DefaultHander(){} protected: int…
1
vote
1 answer

Mock function called by aggregate object using googlemock

I have s scenario where in a local object is instantiated to call a method of that class i.e setSessionId(). Defination of setSessionId is as follows: int Cli::setSessionId() { SessionHandler oHandleSession; return…
CMouse
  • 130
  • 3
  • 19
1
vote
1 answer

Use gtest to write unit tests for a dynamic library

I am new to gtest and gmock but certainly finding it useful. Currently I have built gtest and wrote sample test cases and executed them to see a proper workflow of gtest. As in my main usecase the library I want to unit test is a dll (dynamic…
CMouse
  • 130
  • 3
  • 19
1
vote
1 answer

GTest Typed Test - Using

I want to use 'MyType' from the base class in the 'DoesBlah' test below. #include template struct MemberVariable { T m_t; }; struct Base : public ::testing::Test { template using…
Supervisor
  • 582
  • 1
  • 6
  • 20
1
vote
1 answer

How to repeatedly mock the same function and check for the parameters in each call?

I have a function which expects a method(a different function other than the function under test) to be mocked 8 times. It has 2 arguments. Lets say I am mocking a function - void func(const char *a, const char *b) This function func is called…
C0D3R
  • 339
  • 1
  • 3
  • 12
1
vote
0 answers

Integration Testing Approach for Code C/C++

I have seen this post about Unit Testing for C/C++. I have heard that gtest can be used for Integration Testing. What is the best approach to do Integration Tests? I am afraid that this could replicate Unit/System tests so I am not sure what test…
PySerial Killer
  • 428
  • 1
  • 9
  • 26
1
vote
0 answers

How to set up and use Google Test (as a submodule) with CMake

I have cloned the Google Test repo from GitHub into a personal repository and then added it as a submodule into my main project (using git). I want to be able to use this submodule in my main project by using #include "gtest/gtest.h" The location of…
Blue7
  • 1,750
  • 4
  • 31
  • 55