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

googlemock framework doesn't work with virtual inheritance

It looks like I can not use virtual inheritance when trying to mock interfaces. I need to use virtual inheritance because my code depends on a third-party library. The 3rd-party library uses virtual inheritance to cast from one child to another,…
1
vote
2 answers

Why are `SetUp`/`TearDown` virtual in gtest?

In the googletest Primer, there is an example, where the SetUp/TearDown are virtual. Can someone explain why they are virtual? Here is an example verbatim from the primer: class QueueTest : public ::testing::Test { protected: virtual void SetUp()…
RafazZ
  • 4,049
  • 2
  • 20
  • 39
1
vote
0 answers

Google Test QVector

I am using googletest 1.8 with QT5.9.1 visual studio 2015 I have a container QVector(error) that is populated with data. Basically I want to compare the two containers and check that they have identical populated values using google test. How do i…
agent_bean
  • 1,493
  • 1
  • 16
  • 30
1
vote
2 answers

Passing two arrays as arguments in a gtest

I need to write a unit test (gtest) which passes two values from arrays a[] and b[] respectively. Example: a[] = {40, 45, 50 ,55, 60} b[] = {2, 3, 5, 8, 9, 11} My test case will pass these arrays (a[],b[]) as arguments to a function. Is there a way…
1
vote
1 answer

GoogleMock: How to SetArgReferee according to another input parameter?

I would like to use GoogleMock to mock a service as below: class Request { int req_id; int request; }; class Response { int req_id; int response; }; int request(Response& res, const Request& req) { res.req_id = req.req_id; …
duong_dajgja
  • 4,196
  • 1
  • 38
  • 65
1
vote
0 answers

Gtest EXPECT_EXIT hangs test under valgrind

This test is PASSING, but when run under valgrind, it is HANGING. void testingRaiseSignal() { std::raise(SIGTERM); …
Michal
  • 2,078
  • 19
  • 29
1
vote
1 answer

Gmock - How to set mock function parameter value from an input parameter?

I am using Gmock in my project. I have the following mock function. MOCK_METHOD2(helper, bool(const std::string&, std::string*)); Goal is to set value of parameter 1 to parameter 2 for all mock calls. I did the following. std::string…
balajiboss
  • 932
  • 2
  • 12
  • 20
1
vote
1 answer

Compilation error looser throw specifier for gtest derived classes with HippoMocks member in C++11

I am getting below error while compiling my test cases derived from testing::Test of google test with C++11. Below error will be thrown if my derived class has HippoMock::MockRepository member. looser throw specifier for virtual…
sameer chaudhari
  • 928
  • 7
  • 14
1
vote
0 answers

Cucumber-cpp some LINK errors

I am testing a c++ program using Cucumber framework. Documentation for Cucumber-cpp. Basically, I needed to include some of the library files such as boost, gtest etc. Also, build Ruby Cucumber gem. I have finished all of them. I am currently using…
Shereif SRF
  • 58
  • 1
  • 12
1
vote
0 answers

Is there a commandline testrunner for googletest executables that allows running only the fastest tests?

I am looking for a command line tool that will take googletest executables as an argument and then only runs the fastest tests from that executable. Which those are should be defineable by a given time threshold. At the first run this tool should…
Knitschi
  • 2,822
  • 3
  • 32
  • 51
1
vote
1 answer

Unit testing: Am I doing right when using another method in unit testing a method?

To my best knowledge, unit testing should be done on each public API separately. But, I have been experiencing with a situation in which I have not found out a clear way to unit test each API independently as shown in the following example: class…
duong_dajgja
  • 4,196
  • 1
  • 38
  • 65
1
vote
1 answer

Google Mock - private conversion operator int

I am using a similar code based on the following example: class FOO { private: operator int() const; }; class BARMOCK { public: MOCK_METHOD1(Bar, void(const FOO& foo)); }; Unfortunately the following error message is generated by the…
Iburidu
  • 450
  • 2
  • 5
  • 15
1
vote
0 answers

Error with EXPECT_EQ for create table

During unit Testing of Create Table API, I'm getting the below mentioned error : pankaj:~/Downloads/googletest-release-1.8.0/src$ ./Test.out [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1…
1
vote
1 answer

gcov giving error: No executable lines

I am using gcov to test the code coverage in my project. The gcov is giving me output of the test files that i have written using gtest, but it is not giving me the correct output of the actual implementation files. It gives the message "No…
Tanvir
  • 51
  • 8
1
vote
0 answers

Setting expectations for a GoogleMock causes a memory leak

I am testing a class that takes multiple std::unique_ptr in initialisation. Raw pointers of mock objects are allocated with new, and then passed to an injected unique_ptr. A test without any expectations passes fine. When I add an expectation, I get…
lucas93
  • 11
  • 1