Questions tagged [googletest]
Google's C++ testing framework based on xUnit that runs on multiple platforms.
2,585
questions
0
votes
1
answer
21
views
Where is gmock_gen.py script
I remember that some time ago there was a python script in gtest repository (https://github.com/google/googletest) to generate a mock class automatically. But I can't find it anymore in newer releases....
0
votes
1
answer
20
views
Organizing multi library cmake target with gtests [closed]
I am starting to introduce googletests to our multi-library production codebase and I would like some advice on how to organize better my tests.
We have many internal libraries that we compile as a ...
1
vote
1
answer
18
views
How can a Gtest mock functions to imitate a race between two functions?
I have a function called resize which changes the size of a shared object. I have another function called getsize which gets the size of that shared object. I want to introduce a race between ...
1
vote
2
answers
42
views
C++ Overwrite initializer list in unit test
I have some C++ code like this that I want to unit test:
class Example
{
private:
ExpensiveObject expensiveObject;
public:
Example() : expensiveObject() {
...
1
vote
0
answers
58
views
All tests fail but ~100% line coverage. Why?
I have a function-under-test file and a tester file as below:
Line data Source code
1 : #include<iostream>
2 : using namespace std;
3 3 : ...
0
votes
0
answers
31
views
Debugging google test usinc CLion; breakpoints do not hit
I recently tried to incorporate google tests to our codebase. I can run tests but I cannot seem to figure out how to debug one!
This is my CMakeLists for a test:
add_executable(test_stringUtilities ...
-2
votes
0
answers
29
views
fatal error: gtest/gtest.h: No such file or directory
I am trying to test my c++ file with google test but it shows this error:
fatal error: gtest/gtest.h: No such file or directory
this is my cmake code:
cmake_minimum_required(VERSION 3.16)
project(...
0
votes
2
answers
39
views
How to pretty print GLM math library object values when using Google Test
I am trying to test some math operations with GLM using GoogleTest and pretty print when the assertions fail. I have been following the guides regarding the pretty printing and I found a function ...
-1
votes
1
answer
29
views
Libcurl test with Gmock unit test gives Actual function call count doesn't match EXPECT_CALL: Actual: never called - unsatisfied and active
I'm using Gmock / Gtest to mock unit tests in c++.
Actual Function to be tested is : which is in c language
Class A {
typedef struct response {
char *payload;
size_t size;
} response_t;
int ...
-1
votes
0
answers
14
views
How to create a mock databse unittest
I'm starting to use GTest as my unittest framework and I need to write a test that fetches some data from a database and the next step is to write some data into said database. I know you can use ...
0
votes
1
answer
35
views
googletest SetUpTestSuite() does not run
From : https://google.github.io/googletest/advanced.html#sharing-resources-between-tests-in-the-same-test-suite . I am using 1.11 googletest version.
I am trying to utilize this feature in the ...
2
votes
1
answer
24
views
Saving function arguments to a mock method from a EXPECT_CALL
I have a class that "subscribes" to a signal from a component by calling subscribe(callbackfunction). I am now trying to test this behaviour with gtest/gmock by saving the callback and send ...
1
vote
1
answer
25
views
Trying to match on a c-style array in gmock is failing at compile time
Background:
I'm mocking a hardware i2c transmit function, and trying to match on an array passed into it. This is in an embedded context, hence the c-style arrays and lack of STL containers.
Trying to ...
4
votes
2
answers
122
views
GoogleTest: Increase precision of EXPECT_EQ float failures
I'm seeing failures of an EXPECT_EQ for 32-bit float comparisons that look very odd:
RawDataConverter_Test.cpp:325: Failure
Expected equality of these values:
expectedResult
Which is: 0.0726339
...
0
votes
0
answers
33
views
tbb's private_server and false positive ThreadSanitizer data races
We are getting false positive ThreadSanitizer (tsan) data race warnings on a frequent but inconsistent basis. Though it is well-known that tsan can give false positive warnings, some of which may be ...
0
votes
0
answers
28
views
Static mock injection to dynamically opened library
right now I am testing code from shared library which is opened with dlopen() system call. This library uses functionality that cannot be used in tests, so I would like to mock them, is it possible to ...
-1
votes
3
answers
37
views
How to handle defines in C++ with pre processor instructions (gTest background)?
I am used to handle defines like the following code snipped shows. The paramA is initialized with 1 (edit: defined as 1) and can be used in the code. So far so good...
#define paramA 1
int main(void)
...
1
vote
1
answer
51
views
Validate if delete[ ] is called in google mock
There is a method for deallocating memory using delete operator of c++. I wanted to test it through google test.
void freeMemory(char** test)
{
for(int i=0; i<5; i++)
{
delete[]...
2
votes
2
answers
56
views
Parametrized tests with parametrized SetUp()/TearDown()
I have a test fixture that shares most of the test code. The variations are mostly from a parameter value. I would like to create SetUp() / TearDown() for them, but they (obviously) can't be called ...
0
votes
1
answer
19
views
How to specify a bazel test env setting for a cc_test?
I'm trying to specify a env variable for a bazel test. I've tried the following but it fails:
cc_test(
name = "some_test",
size = "small",
deps = ["some_thing&...
1
vote
1
answer
37
views
Is there a way to only mock functions only when I need in Google mock?
I have a mock
class mockA: public A{
public:
.......
MOCK_MOTHOD0(functionB, bool());
}
and functionB is a protected virtual function in class A. I can use the mock method in my ...
1
vote
1
answer
29
views
GoogleMock - Returning a value based on mocked function variables
I'm trying to mock a function that accepts a struct and returns another one. Something like
struct InParams {
int important_value;
int other_value;
}
struct OutParams {
int same_important_value;...
3
votes
0
answers
42
views
How to write EXPECT_CALL for the mock function with return type std::vector<std::tuple<int,int>> in gtest/gmock
I have a member function in the c++ class with return type std::vector<std::tuple<int,int>>
code.cpp
class A
{
A();
~A();
std::vector<std::tuple<int,int>> function();
};
...
0
votes
2
answers
61
views
Using FRIEND_TEST to test private functions of a class in another namespace
I'm trying to use GTest's FRIEND_TEST() macro to enable testing of some private functions from another namespace. However, I can't get past some errors, though I must be missing something simple.
I ...
0
votes
2
answers
30
views
c++ GMock SetArgReferee as CStringArray
Using c++11 with MFC, and trying to create some unit tests with gtest 1.7, I've encountered a problem. I want to mock a nasty method without changing the declaration or the definition of the method ...
0
votes
0
answers
47
views
Comparing regular expression on stderr for EXPECT_EXIT from GoogleTest
I'm trying to figure out how to compare strings in error messages using EXPECT_EXIT from GoogleTest.
Everything works fine when I add common characters, but it doesn't work for characters like [](){}.
...
1
vote
0
answers
53
views
Why does the gtest death test loop indefinitely
In my project we imitate blockbox testing using gtest. For that reason we implemented a mockMain() function containing all relevant code that should be inside the blackbox. Then we use the TEST_F ...
0
votes
1
answer
29
views
gmock: force mocking out of a class method without defining and referencing a mock class?
the normal pattern of gmock testing is
class MyMockClass : public MyRealClass {
/// swap out behavior of an existng method
MOCK_method(some_method .....);
}
TEST()...
2
votes
2
answers
37
views
Google mock invoke function with parameters
static bool helper(int a){
// do something here
return true;
}
class ProxyMock : public Proxy
{
public:
MOCK_METHOD1(functionA, bool(
int a
...
0
votes
1
answer
68
views
Why does Bazel http_archive rule not download archive?
I'm a Bazel newbie and am working through the C++ guide here, trying to include an external testing library (gtest): https://bazel.build/tutorials/cpp-use-cases#include-external-libraries
This is my ...
0
votes
1
answer
53
views
CMake: can't use gtest built from source with error " 'gtest/gtest.h' file not found"
I was trying to build GTest from source and then link my target to it using cmake. But I see this error
mygtest % cmake --build build
[ 50%] Building CXX object CMakeFiles/hello_test.dir/mytest.cpp.o
/...
0
votes
0
answers
26
views
"No tests found" in vscode "Testing" tab for c++ google test
VSCode version: 1.67.2
My google test application is built and run successfully from VSCode by selecting the target and I can see the test output in the terminal, set breakpoint and such. However, ...
1
vote
1
answer
50
views
How to use an argument as return value in gmock
I have the following call:
EXPECT_CALL(myMock, myFunction(someSpecifiedParameter, _, _))
.WillOnce(DoAll(SaveArg<2>(&bufferSize), Return(make_pair(Success, bufferSize))));
I'm trying ...
1
vote
1
answer
53
views
Variables in Google Test Fixtures
Why TEST_F can access the member variable in a class without using any scopes? e.g.,
class ABC : public ::testing::Test
{
protected:
int a;
int b;
void SetUp()
{
a = ...
3
votes
1
answer
49
views
Show failed function instead of macro in gtest
currently I'm working on creating new tests using gtest. There are some cases where I use same groups of EXPECT_EQs, so I wrap them up in a function. And now when particular test failes, it prints out ...
0
votes
0
answers
20
views
C++ Google test - exporting additional information like 'author' and 'project' to XML report
I am using the output parameter of google test like
--gtest_output=xml:Reports\fooReport.xml
However some XML attributes like author and project won´t be exported as the tool gtest2html might expect....
1
vote
2
answers
53
views
How to reduce a C array of strings to unique values
I am working on a basic framework to dynamically allocate arrays. In this case it is an array of strings. I am trying to create a function to delete all non-unique string values from the array and ...
1
vote
1
answer
42
views
Xml Generation from Google test does not show skipped test cases
I am using google test framework for doing unit testing in c++. I have few test cases which i have disabled using DISABLED_ before test name and some tests are skipped using GTEST_SKIP(). This is ...
1
vote
0
answers
55
views
VectorCast vs GTest for unit tests
I am a newbie at VectorCast. I have developed some unit tests with VectorCast. But I am still not confident with VectorCast(maybe, I am wrong:) ).
For unit tests, I don't think VectorCast could work ...
0
votes
0
answers
40
views
Mocking serial port with googlemock
I want to mock a serial port on a Raspberry Pi using google mock. The mocking code works, but the serial port does not open. This causes the tests to fail. The code is shown below.
class MockSerial : ...
-1
votes
2
answers
53
views
boost::asio::io_context::stop segfalt in gtest setup and teardown
Using C++17. I am trying to setup a gtest fixture that will create a fresh io_context to run timers on for each test case. My test segfault about 90% of the time. If I debug and step very slowly, I ...
-3
votes
1
answer
244
views
How do I build and use googletest (gtest) and googlemock (gmock) with gcc/g++ or clang?
Googletest (gtest) seems to be an immensely popular unit test framework and I'd like to learn how to build it stand-alone on the g++ compiler, simply and easily, so I can test small libraries and one-...
0
votes
1
answer
27
views
GMock cannot disambiguate overloaded function
We have a mock class with an overloaded method. Variable/class names have been altered
class MockBuilderClass
: public IBuilder
{
public:
MOCK_METHOD1(Method, IBuilder& (const std::vector<...
-2
votes
1
answer
38
views
C++ google test, mocks not called on inherited classes
As said in the title, I try to test my code using google test, but I get some issue on inheritance of mocks.
I will further present the structure of my code:
file1.hpp
struct A: virtual public testing:...
0
votes
1
answer
38
views
googletest - mocking abstract class
I am learning mocking and using googletest I created MockServer class that should mock the abstract class IServer:
class IServer
{
virtual void writeData(QString buffer) = 0;
virtual ...
1
vote
1
answer
55
views
Run each test in a new container
I have google test based test suite. Since the tests manipulate the filesystem and do other things that I don't want to be left behind in case of a test crash, besides just not playing nicely with ...
2
votes
1
answer
77
views
Is there a way to stop GoogleTest after a specific test is run, whether it passes or fails?
I have a large number of unit tests run through GoogleTest. Currently one of them (call it fooTest) is failing when the full test suite is run, but passing when run alone. So one (or more then one) of ...
0
votes
0
answers
150
views
How to use Visual Studio and CMAKE and GTEST to generate code coverage report
I'm trying to generate a code coverage report using visual studio 2022, using cmake + gtest, but my vs2022 always doesn't work. I've rummaged through google and microsoft documentation and couldn't ...
0
votes
1
answer
84
views
C++ google test fail for multi threads
I am having following C++ code and corresponding unit tests in google test. I am studying book on Modern C++ programming using Test Driven development. Below code is crashing in scale tests. Problem ...
0
votes
1
answer
39
views
How can I use member functions of google unit test case in thread defined in the unit test?
I have a google unit test where I've defined a few functions in it. It looks like the following
class MyUnitTest {
protected:
void SetUp() override;
void TearDown() override;
void ...