FAQ Database Discussion Community


How to check with Google Test zero or one function call?

c++,unit-testing,googletest,googlemock
I want to write a test, that invokes 2 functions in different threads, and I expect that depending on which function will work first happpens this: EXPECT_CALL(foo, bar(arg_1)); or this: EXPECT_CALL(foo, bar(arg_1)).RetiresOnSaturation(); EXPECT_CALL(foo, bar(arg_2)).RetiresOnSaturation(); EXPECT_CALL(foo, bar(arg_1)).RetiresOnSaturation(); exactly in this order. What is the easiest way to do it? I'm pretty...

Is it possbile to show how many EXPECT_* calls are made in the output of gtest

unit-testing,googletest
I found the google test framework shows only failure reports. Is it possible to show the pass checks in the report (stdout and xml)? For example, show the EXPECT_* count in the report. Thanks for helping....

Google Test separate project - How to get tests running against the C++ project

c++,cmake,googletest,clion
I am trying to figure out how to run Google Test against my C++ project using CMake. So far I have created a project called Simple and a Google Test project called SimpleTest. For the Simple Project Here's my CMakeLists.txt file: cmake_minimum_required(VERSION 2.8.4) project(Simple) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES main.cpp NewCppClass.cpp...

Create a new “Shell Tool” target in Xcode for the use of Google Test

c++,xcode6,googletest
I am trying to add googletest framework to my existing C++ project. And I am following their XcodeGuide. However, I cannot get over this following step. Create a new "Shell Tool" target in your Xcode project called something like "UnitTests" So question: what is a shell tool target for a...

How to compile and link google tests in C++ project in Visual Studio 2013 but with Gtest installed by NuGet Package Manager?

c++,visual-studio,linker,nuget,googletest
I have Microsoft Visual Studio 2013 Community Edition on Windows 7. I want to install gtest and gmock for C++ in newer way than downloading headers and binaries or compiling by myself. I found Tools > Nuget Package Manager > Manage Nugets Packages For Solution I chosen Online, then typed...

How to compare special fields in google mock?

c++,testing,googletest,googlemock
I have got question connected with google test. I would like to ask if while inducing "EXPECT_CALL(*A, some_method(mes1));" in test case there is possiblity to compare fields included in mes1 class. struct Mes { int a; }; //short section of test case: Mes mes1 = Mes(); EXPECT_CALL(*A, some_method(mes1)); I would...

Global include path on Windows on VS2013

c++,windows,visual-studio-2013,include,googletest
I should add a global include path to my system (i.e. it's Google Test so I need to include "C:\gtest\include") I appended it to the PATH environment variable and restarted VS2013. However, VS2013 still complains about the missing .h files. What's wrong with this IDE?!?...

GoogleTest CMake and Make tests not running

c++,linux,makefile,cmake,googletest
I admit I have a unique situation. We build our application using Make. But my IDE, CLion, uses CMake. So I have tried to set up GoogleTest to run on both (kind of). I can compile my code both ways (using make at the command line and build from my...

Don't know where exception was thrown using google-test

c++,exception,visual-studio-2013,exception-handling,googletest
We are using Google Test as our C++ unit testing framework. But I ran into a painful situation and don't know how to deal with. Basically, when there is an uncaught exception in the code, I got the following error message printed in the console and get a FAILED. Obviously,...

EXPECT_CALL check if parameter contains given subset

c++,googletest,matcher,gmock
I'm using gtest & gmock and want to set expectations on a function that is called with a set. I want to make sure this set contains several elements. Something like this: EXPECT_CALL(*mView, SetHighlightedCells(Contains(AllOf(c5, c6)))); I know I can specify the full set, EXPECT_CALL(*mView, SetHighlightedCells(UnorderedElementsAre(c5, c6, ...and all the rest..)));...

Error: ‘to_string’ is not a member of ‘std’ when compiling in command line with gcc 4.8.2, works in NetBeans?

c++,c++11,netbeans,googletest,g++4.8
I am doing tests for my code with GoogleTest (1.7.0). I must have the tests compiling in both NetBeans (8.0.2) and straight from command line. NetBeans has GoogleTest integrated as suggested here: https://youtu.be/TS2CTf11k1U. I have also build GoogleTest from the command line (in different place) with the instructions provided with...

this pointer gets set to null when entering function call stack - happening with Google Test under gdb

c++11,gdb,cygwin,googletest,g++4.8
(gdb) list 95, 195 95 int BishopArranger::FillAndRecurse(int cursor) 96 { 97 if (cursor == _solutionVec.size()) 98 { 99 return 1; 100 } 101 102 unordered_set<tuple<int, int>> candidates = GetCandidates(cursor); //kn 103 if (candidates.empty()) 104 { 105 return 0; 106 } 107 108 int sum = 0; 109 for (unordered_set<tuple<int, int>>::iterator...

How to ask Cmake output googletest detailed result

c++,cmake,googletest
Normally, if I type make test with the cmake generated makefile, it will show something like this: Start 1: UnitTest 1/2 Test #1: UnitTest .........................***Failed 0.01 sec Start 2: PerfTest 2/2 Test #2: PerfTest ......................... Passed 0.01 sec 50% tests passed, 1 tests failed out of 2 Total Test time...

How to encode multiple distinguishable items back to back with protobuf?

c++,protocol-buffers,googletest
So, I have a unit test where I'm trying to ensure that encoding and decoding is sound. Basically, I kind of want to be able to serialize multiple different C++ objects into a string, and then write that string into a file. This is what I have so far: Here's...

Using Visual Studio to do Code Coverage on gtest unit tests for native VS C++

c++,unit-testing,code-coverage,googletest
Friends, I have been looking at unit test code coverage tools for the last 2 weeks, evaluating them for our specific needs. The last one I would like to evaluate is Visual Studio's own code coverage for native C++ unit tests. In our solution, we have the following: full Visual...

GoogleTest CMake doesn't recognize TEST_F: Like it's not recognizing GTest something

linux,cmake,make,googletest
OK, I admit it, this is a unique case. When we build our application we are using make, so I've included my tests in a test folder under src. Then at the same level as our release folder we have created a unit-test folder that includes all of our source...

How to initialize constant string for multiple tests in google test?

tdd,googletest
I'm using google test and I have a cpp-file containing several tests. I would like to initialize a string with the current date and time when starting the first test. I would like to use this string in all other tests, too. How can I do this. I've tried the...

Google Test pre-build VS 2013

c++,visual-studio,linker-error,googletest
I have a solution which was compiled with compiler VS2008. It was working perfect. It is instrumented with Google Test and the Google Test library is linked to the solution. the gtest.lib should be compiled with the same compiler as the solution itself, as far as I know. Now, I...

Creating one binary for multiple unit tests in Google's C++ Testing Framework

c++,unit-testing,cmake,googletest
Currently I have a test folder with multiple source files for each test. On CMake, I previously defined a binary for each source file but decided that I should now combine all of them into a single binary and make use of the filters in GTest to select which tests...

Automatically Generate Google Mock Methods?

c++,methods,googletest,googlemock
I'm fairly new to C++ and Unit testing and I'm learning to use Google Mock and Google Test right now to test some code that I'm working with. Instead of writing all of the Google Mock methods manually, is there a way to point Google Mock to your class and...

Why the compiler does not recognize Google Mock wildcard?

c++,googletest,googlemock
When I try to use: ON_CALL(mock, foo(_)) Compilation error is thrown: Error 1 error C2065: '_' : undeclared identifier I am using visual studio 2012....

Do you only need to build the googletest library once?

c++,cmake,make,static-libraries,googletest
So firstly I'm new to testing frameworks and relatively new to C++ but am trying to wrap my head around GoogleTest. I'm working on a Windows machine, running "Git for Windows" (MSYS) and MinGW whilst using Sublime Text as my code editor. I am using make as my build tool,...

GTest's output has no colors when built with cmake+ninja and executed automatically

cmake,googletest,ninja
I'm trying to configure CMake and ninja as a build system for my project. Except the app itself I have an extra executable for unit tests powered by gtest. I thought it would be nice to have them executed automatically whenever they are built. Here's how I made it: ├──...

Call code only once in Gtest per class

c++,googletest
I am using gtest as my testing framework. I am looking for a specific function that will be called only once. So far, I have seen SetUp and the constructor of the class. But it seems like they are both called for each test. According to this example, the constructor...

How to test method in google test, using std::function?

c++,unit-testing,testing,googletest,googlemock
I would like to test method "methodToTest" in class A: typedef std::function F_global; struct A { F_global m_F_global; A(F_global m_F_global) : p_F_global(m_F_global) {} void methodToTest() { m_F_global(5); } }; I have got a mock class: class RunMock { public: MOCK_METHOD1(run, void (int)); }; Below I have got a test case:...