尝试引用已删除的函数单元测试

Attempting to Reference a Deleted Function UnitTest

我想为 class 创建一个单元测试,其中包含一个将模板参数作为参数的虚方法,但我在编译代码时遇到了问题。我已经包含了我想要实现的目标的最小示例。我无法编译我错过了什么?

tst_templates.h 文件。

    #include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <gmock/gmock-matchers.h>

#include "mockview.h"
#include "configuration.h"

using namespace testing;

class MyTest : public ::testing::Test
{
    public:

protected:

    FRIEND_TEST(MyTest, Print);

    virtual void SetUp()
    {


    }

    virtual void TearDown()
    {

    }
};

TEST_F(MyTest, Print)
{
   MockView<Configuration> View;
   Configuration c;
   View.Print(c);
}

MockView.h 文件

#ifndef MOCKVIEW_H
#define MOCKVIEW_H

#include <gmock/gmock.h>
#include "iview.h"

template <typename T>
class MockView : IView<T>
{
    public:
    MOCK_METHOD1_T(Print, void(const T &Settings));

    virtual ~MockView(){}
};

#endif // MOCKVIEW_H

Configuration.h

#ifndef CONFIGURATION_H
#define CONFIGURATION_H

#include "iconfiguration.h"
#include <iostream>

class Configuration : public IConfiguration
{
public:
    Configuration()
    {

    }

    void Print()
    {
        std::cout << "Configuration Print" << std::endl;
    }

    ~Configuration()
    {

    }
};

#endif // CONFIGURATION_H

IView.h

#ifndef IVIEW_H
#define IVIEW_H

template <typename T>

class IView
{
    virtual void Print(const T& settings) = 0;
    virtual ~IView(){}
};

#endif // IVIEW_H

template <typename T>
class IView
{
    virtual void Print(const T& settings) = 0;
    virtual ~IView(){}
};

作为 class,方法 Print~IView 是私有的,因此您甚至无法从派生的 class 访问它们。将它们设为 public 或将 class 更改为 struct 以将默认可见性更改为 public