GoogleMock问题使用Eclipse构建C ++简单代码

时间:2019-05-24 17:42:35

标签: c++ eclipse googlemock

在MobileTest.h中,我有:

#include <gtest/gtest.h>
#include <gmock/gmock.h>
using ::testing::Return;

#include "Mobile.h"

class MockedCamera : public Camera {
public:
    MOCK_METHOD0(ON, bool());
    MOCK_METHOD0(OFF,bool());
};

Mobile.h代码:

#ifndef __MOBILE_H__
#define __MOBILE_H__

#include <iostream>
using namespace std;

#include "Camera.h"

class Mobile {
private:
    Camera *pCamera;
public:
    Mobile();
    Mobile(Camera *pCamera);
    bool powerOn();
    bool powerOff();
    virtual ~Mobile(){};
};

#endif /* __MOBILE_H__ */

Camera.h头文件

#ifndef __CAMERA_H__
#define __CAMERA_H__

#include <iostream>
using namespace std;

class Camera {
public:
    Camera();
    virtual bool ON();
    virtual bool OFF();
    virtual ~Camera(){};
};

#endif /* __CAMERA_H__ */

这是Udemy C ++课程的简单代码,但是当使用eclipse构建时,它没有移动测试就给我错误。h MOCK_METHOD0宏调用:

Symbol 'ArgumentCount' could not be resolved
The type 'testing::internal::FunctionMocker' must implement the inherited pure virtual method 'testing::internal::UntypedFunctionMockerBase::UntypedPerformAction' 

这是项目的makefile,当我尝试使用make命令时,它给了我很多与gtest相关的错误:

SRC = $(wildcard src/*.cpp test/*.cpp)

OBJS = $(SRC:.cpp=.o)

CXXFLAGS = -std=c++14

LIBS = -pthread libgtest.a

INC = -I googletest/googletest \
      -I googletest/googletest/include \
      -I googlemock/googlemock \
      -I googlemock/googlemock/include \
      -I src \
      -I test

EXE = mobileTest.exe

all: $(OBJS)
    cp -f $(OBJS) .
    g++-7 -o $(EXE) $(CXXFLAGS) $(OBJS) $(LIBS) $(INC)
    rm -f $(OBJS)

%.o: %.cpp
    g++-7 -c $(CXXFLAGS) $(INC) $< -o $@

.PHONY: clean

clean:
    rm -f *.o *.exe

建议?

1 个答案:

答案 0 :(得分:0)

我将gtest和gmock用作库。

gtest库的项目文件包含以下源文件

SOURCES += ../googletest/src/gtest.cc \
../googletest/src/gtest-death-test.cc \
../googletest/src/gtest-filepath.cc \
../googletest/src/gtest-port.cc \
../googletest/src/gtest-printers.cc \
../googletest/src/gtest-test-part.cc \
../googletest/src/gtest-typed-test.cc

gmock库的项目文件包含以下源文件

SOURCES += ../googlemock/src/gmock-cardinalities.cc \
       ../googlemock/src/gmock-internal-utils.cc \
       ../googlemock/src/gmock-matchers.cc \
       ../googlemock/src/gmock-spec-builders.cc \
       ../googlemock/src/gmock.cc