2,886 questions
-1 votes
0 answers
71 views
Should I exclude virtual destructor from code coverage? [closed]
We have a virtual destructor declared in our class: class HeightCalculator { public: HeightCalculator() = default; virtual ~HeightCalculator() = default; LCOV then complains that we don’t cover ...
Best practices
0 votes
3 replies
105 views
Testing equality and inequality comparison
Philosophically, does GoogleTest's ASSERT_EQ(x, y) mean "check that x is equal to y" or "evaluate x == y and check that the result is truthy"? In the former case, then struct S s1, ...
Best practices
0 votes
5 replies
77 views
How to intercept calls to a function that returns file paths in gmock
I am working on a C++ code base that has a function called "getConfigFilePath()" in name space "utils" which returns the file path to a config file. The config file is really hard-...
0 votes
0 answers
62 views
Assert global condition after every test case
In my gtest, every individual case may potentially modify a global variable, so it would be ideal to check its value against a system library call after every test case. But when I attach a testing::...
6 votes
1 answer
171 views
Why does GTest block operator==/!= lexical scope lookup?
The file gtest.h from Google Test includes these lines. // This block of code defines operator==/!= // to block lexical scope lookup. // It prevents using invalid operator==/!= defined at namespace ...
1 vote
1 answer
81 views
In gtest what is the difference between TestEventListener::OnTestCaseStart and OnTestStart
Both methods are offered, but what is the difference?
1 vote
1 answer
82 views
Diff btw "Invoke( lambda )" and directly calling a lambda when we use Google Mock EXPECT_CALL
Since I learnt to use Google Test/Mock framework, I allways used the form to setup an expectation as following: EXPECT_CALL( mock_obj, mock_method ).WillOnce( Invoke( []() { do_things; } ) ); Few ...
0 votes
0 answers
39 views
Different behaviour of Visual Studio when two users link the same code [duplicate]
My colleague can build our project, while I get the following linker errors: 26>gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match ...
0 votes
1 answer
69 views
Gmock WillByDefault triggered despite matching EXPECT_CALL
I am using the WillByDefault(testing::Throw(...)) trick to terminate the test early, as described in https://stackoverflow.com/a/79534623/2894535 However, it seems to randomly trigger in some cases, ...
0 votes
1 answer
130 views
Should i make separate constructors for gtest?
I'm dealing with code that should be unit-tested with gtest and I can't quite understand the following Right now I have two class constructors: // Base constructor ClassName::ClassName(ConfigLib ...
1 vote
0 answers
256 views
How do I enable INSTANTIATE_TEST_SUITE_P in google tests?
I get an errors when trying to work with INSTANTIATE_TEST_SUITE_P. The minimum non-working example that I got is: #include "pch.h" class SimpleTest : public ::testing::TestWithParam<int&...
5 votes
1 answer
89 views
Return alternating values from mock
I want to test a function where one of its mocks should return alternating values many times. So e.g. I need something like this: EXPECT_CALL(my_mock, foo(_)) .WillOnce(Return(A)) .WillOnce(...
2 votes
1 answer
106 views
How can I express a disjunctive EXPECT_EQ so that failing tests' output is easy to read?
I have the following logic in one of my tests: EXPECT_TRUE(a == x || b == y); Is there a neat way to rewrite it to EXPECT_EQ so that I can see the values a, b, x, y in the failing test's output? If ...
5 votes
1 answer
444 views
How to stop gtest on first unexpected gmock call
Is there an equivalent to ASSERT_* for EXPECT_CALL, which ends the test on first uninteresting/unmatched call? I am using gtest+gmock to test HW register programming sequences, so all EXPECT_CALL are ...
0 votes
1 answer
83 views
Asynchronous logging and printf-debugging
I use async logging and, in cases where I cannot debug with debugger attached, I'm forced to update my code to flush logs on each statement. Something like LOG("something"); LOG_FLUSH(); ...