C++ MOCK#u方法名称后面必须跟';::';必须是类或命名空间名称
给定一个接口类Foo:C++ MOCK#u方法名称后面必须跟';::';必须是类或命名空间名称,c++,visual-studio,googletest,googlemock,C++,Visual Studio,Googletest,Googlemock,给定一个接口类Foo: #ifndef FOO_H #define FOO_H #include <string> class Foo { public: Foo() = default; virtual ~Foo() = default; virtual void bar(std::string msg) = 0; }; #endif 还有一个愚蠢的测试: #include "pch.h" #include "gtest/g
#ifndef FOO_H
#define FOO_H
#include <string>
class Foo
{
public:
Foo() = default;
virtual ~Foo() = default;
virtual void bar(std::string msg) = 0;
};
#endif
还有一个愚蠢的测试:
#include "pch.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "MockFoo.h"
using ::testing::NiceMock;
TEST(SillyTests, Silly)
{
std::string msg = "Hello, world!";
NiceMock<MockFoo> mock_foo;
EXPECT_CALL(mock_foo, bar)
.Times(1);
mock_foo.bar(msg);
}
将鼠标悬停在MOCK_方法上
会显示几个静态断言,但它们似乎不正确。这些措施包括:
应该用括号括起来(它是)“(std::string)”
应该用括号括起来(同样是)“(覆盖)”
- 签名必须是函数类型,可能返回类型包含不受保护的逗号(它是type
,添加括号无法更正此问题)void
- 此方法不接受“1”参数。用不受保护的逗号将所有类型括起来
gmock版本是1.10.0,Google测试适配器版本是1.8.1.3。解决了这个问题。googlemock和googletest不共享同一版本是原因。将googlemock降级到v1.8.1版本纠正了这个问题。是否包含
?你的GenericLogger头有防护装置吗?
包含在GenericLogger.hpp中,我在GenericLogger、傻瓜日志和模拟日志中有防护装置(#ifndef
,而不是#pragma once
)。好的,我不得不问一下,因为这不完全是一个问题。如果你能给我们其中一个,那会有帮助:-)啊,给我一些,我会这样做。你使用的是哪个版本的谷歌测试和谷歌模拟?
#include "pch.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "MockFoo.h"
using ::testing::NiceMock;
TEST(SillyTests, Silly)
{
std::string msg = "Hello, world!";
NiceMock<MockFoo> mock_foo;
EXPECT_CALL(mock_foo, bar)
.Times(1);
mock_foo.bar(msg);
}
MOCK_METHOD1(debug, void(std::string msg));