gmock

How to mock a derived class that calls its base class methods?

故事扮演 提交于 2021-01-28 03:05:25
问题 I am unit testing a derived class and want to EXPECT_CALL that a certain method belonging to its base class is called. For example: class Base { public: void move(int x, int y); }; class Derived: public Base{ public: RESULT update(); private: int age; }; HRESULT Derived::update(void) { int param1 = 5, param2 = 10; move(param1, param2); age++; return SUCCESS; } I can't just create a mock for Derived and expect move since there is no dependency and the actual move() will be called. How can I be

with Googletest i am not able to mock system function

别来无恙 提交于 2021-01-07 10:42:32
问题 I am trying to mock the system fun ioctl and socket but it is always calling the original definition of system function. Here is the gtest code i have written using gmock. Please go through the code and help me find what is wrong. Is there a way to mock the system functions using gmock in unit testing. If any please provide me with an example code that mocks system function. In the test.hpp file class SystemFun { public: virtual ~SystemFun() {} virtual int ioctl(int inetSocket, int counters,

with Googletest i am not able to mock system function

自古美人都是妖i 提交于 2021-01-07 10:41:42
问题 I am trying to mock the system fun ioctl and socket but it is always calling the original definition of system function. Here is the gtest code i have written using gmock. Please go through the code and help me find what is wrong. Is there a way to mock the system functions using gmock in unit testing. If any please provide me with an example code that mocks system function. In the test.hpp file class SystemFun { public: virtual ~SystemFun() {} virtual int ioctl(int inetSocket, int counters,

Installing gtest with conan

一世执手 提交于 2020-12-13 03:54:48
问题 I am about to change to conan, in the hope that is will simplify installing my package by my users. It was OK, until I started to add gtest to my package. During install, I receive messages gtest/1.8.1@bincrafters/stable: Package installed conanfile.txt imports(): Copied 4 '.a' files: libgmockd.a, libgtestd.a, libgmock_maind.a, libgtest_maind.a However, during build I receive: /usr/bin/ld: cannot find -lgmock_maind /usr/bin/ld: cannot find -lgmockd /usr/bin/ld: cannot find -lgtestd My

CLion 使用googleTest demo

房东的猫 提交于 2020-12-06 19:47:28
CLion 使用googleTest demo 1. 基本步骤 创建C/C++项目 将googleTest克隆下来 git clone https://github.com/google/googletest.git 将整个googleTest复制到项目里 配置CMakeLists.txt,下面是示范 cmake_minimum_required(VERSION 3.9) project(GTest) set(CMAKE_CXX_STANDARD 11) set(googleTestDir ./googletest) #Add the google test subdirectory add_subdirectory(${googleTestDir}) #include googletest/include dir include_directories(${googleTestDir}/googletest/include) #include the googlemock/include dir include_directories(${googleTestDir}/googlemock/include) set(SOURCE_FILE src/add.cpp test/addTest.cpp src/add.h ) add_executable(GTest ${SOURCE

Mock static method from external Class (that I can't change!)

删除回忆录丶 提交于 2020-12-06 08:09:12
问题 I want to mock (with gmock) a static function from a class that I can't change. A is the class that I want to mock: Class A { public: static std::string get_id(); ... } B is my class that I want to test with gmock: Class B { public: B(A *a_ptr); ... std::string foo(); private: A *m_a_ptr; } B::B(A *a_ptr) : m_a_ptr(a_ptr) { } std::string B::foo() { id = m_a_ptr->get_id(); return id; } How can I mock the method get_id without changing the class A? 回答1: Static dependency injection and GMock