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

Compound Tests with GoogleTest?

If I have something like: ASSERT_TRUE(RANGE(val1, val2, abs_err) || RANGE(val1, val3, abs_err)); How would I use ASSERT_NEAR instead of ASSERT_TRUE? I've attempted to break up the statement into two ASSERT_NEAR statements, like below, but the test…
Irfan Hossain
  • 59
  • 1
  • 10
1
vote
1 answer

Object argument to mock EXPECT_CALL

I have a simple mock class: class MockCanInterface : public lib::CanInterface { public: MockCanInterface() : CanInterface({"mock"}) {} MOCK_METHOD1(Write, bool(const lib::CanFrame& frame)); MOCK_METHOD1(Read, bool(lib::CanFrame*…
ilya1725
  • 4,496
  • 7
  • 43
  • 68
1
vote
0 answers

Typed tests with Google Test show a warning in Visual Studio 2017

I am trying to learn to use Google Tests, so I have this template class for which I want to used typed tests. This is the tests file that shows a warning: #include "gtest/gtest.h" #include "gtest/gtest-typed-test.h" #include…
p0licat
  • 45
  • 1
  • 10
1
vote
1 answer

Use gcc+gtest+mockcpp in windows,the mock does not work at all

When I build the mockcpp lib mockcpp.lib in MSVC format and build my unit test project in MSVC, it works well. When I specify the CMake generator for the mockcpp to Unix Makefile, specify native compilers to cygwin64/bin/gcc.exe and…
1
vote
1 answer

google mock - EXPECT_CALL triggers even though function has different argument

I have EXPECT_CALL(MockObj, func("abc")).Times(1) and MockObj is a NiceMock In my function under test, there is a call MockObj.func("def") in addition to MockObj.func("abc"). I would expect that the reasonable thing to do is for Google Mock to say…
Bob
  • 4,576
  • 7
  • 39
  • 107
1
vote
2 answers

Is it possible to mock a called function return value using gtest or gmock?

I am new to gtest and gmock please let me understand how to mock the called function. Which will also help me in code coverage. #include #include "gtest/gtest.h" int ret() { return 5; } class A { public: A(); int…
Dipankar Saha
  • 302
  • 1
  • 5
  • 15
1
vote
1 answer

google mock - save EXPECT_CALL then re-use and change clauses

Let's say you have this: EXPECT_CALL(MockClass_obj, f1(55)).Times(1); // use the expectation // ... // Now clear it Mock::VerifyAndClear(&MockClass_obj) Is it possible to 1) Save the expectation AND 2) Re-use it later and change the clauses? From…
Bob
  • 4,576
  • 7
  • 39
  • 107
1
vote
1 answer

google mock - how to expect function to NOT be called with set of parameters

Let's say you have void Class::func(Type_t arg) I want to say this function can be called except with arguments arg1 or arg2 or ... argN Is this the correct way? EXPECT_CALL(Class_MockObj, func(arg1)).Times(0); EXPECT_CALL(Class_MockObj,…
Bob
  • 4,576
  • 7
  • 39
  • 107
1
vote
1 answer

/usr/bin/ld: cannot find -lgmock on ubuntu while running gmock program

I am trying to compile simple gmock example on my ubuntu vmware(16.04 LTS) and getting below error while doing "make" I have below files - "test.h" class CBasicMath { public: CBasicMath(){} virtual ~CBasicMath() {} virtual int…
user2564083
  • 23
  • 3
  • 8
1
vote
1 answer
1
vote
0 answers

C++11 deduce type to return from gmock's EXPECT_CALL macro

I had the following class and its mock: struct Logger { virtual void logWarning(string msg); }; struct LoggerMock : Logger { MOCK_METHOD1(logWarning, void(string)); /*! Sets expectation that some warning will be logged */ …
Zak
  • 464
  • 3
  • 13
1
vote
2 answers

Google tests don't work with class in other project in solution

I'm trying to test my simple class for building (that it has good constructor). File TestClass.h #pragma once class TestClass { public: TestClass(); }; File TestClass.cpp #include "TestClass.h" TestClass::TestClass() { } And then I add new…
1
vote
1 answer

General questions on parameterized test in googletest

background:I am writing a Session table for incoming traffic. This table should hold all active UDP/TCP connections. I am using googletest package to test my implementation. I prepare a parameterised test based on fixture in the following…
amigal
  • 517
  • 3
  • 8
  • 21
1
vote
1 answer

g++ fatal error when compiling Google Test

I am trying to compile some tests with Google Test. I am using the sample makefile that comes with GTEST, but from a different directory. I added some make targets to compile my tests and sources, but left the Google Test bits untouched, however…
1
vote
3 answers

Disable whole test case in gtest

How can one disable a complete test case in gtest? (all the tests in a test case, not just individual tests) The formatting proposed in the gtest doc is to organise the tests in the following fashion: class1test.cpp: Test(Class1Test, TestA) { …
Basile Perrenoud
  • 4,039
  • 3
  • 29
  • 52
1 2 3
99
100