googlemock

How to set up both GoogleTest and GoogleMock in Visual Studio?

╄→гoц情女王★ 提交于 2020-06-01 05:07:32
问题 With Visual Studio 2017/2019 it is really easy to set up a new Google Test project and start writing tests (as long as you don't mind using older versions of GoogleTest versions anyway). But what about using GoogleMock as well? You would think that since Google combined gtest/gmock some time ago that this would just work. Just #include "gmock/gmock.h" and mock away. But no, the GoogleTest NuGet package that is automatically added by the template does not include the gmock folder at all.

How to set up both GoogleTest and GoogleMock in Visual Studio?

荒凉一梦 提交于 2020-06-01 05:06:48
问题 With Visual Studio 2017/2019 it is really easy to set up a new Google Test project and start writing tests (as long as you don't mind using older versions of GoogleTest versions anyway). But what about using GoogleMock as well? You would think that since Google combined gtest/gmock some time ago that this would just work. Just #include "gmock/gmock.h" and mock away. But no, the GoogleTest NuGet package that is automatically added by the template does not include the gmock folder at all.

google mock - can I call EXPECT_CALL multiple times on same mock object?

对着背影说爱祢 提交于 2020-05-20 09:33:41
问题 If I call EXPECT_CALL twice on the same mock object in the same TEST_F . . . what happens? Are the expectations appended to the mock object or does the second call erase the effects of the first call? I found The After Clause which appears to imply that multiple calls to same mock + EXPECT_CALL are allowed. 回答1: Yes, you can call EXPECT_CALL on the same mock object multiple times. As long as you assure that all EXPECT_CALL were called before the mocked methods were actually used. Otherwise

Interleaving EXPECT_CALL()s and calls to the mock functions

不想你离开。 提交于 2020-05-15 04:06:59
问题 The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined . In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions. Does anyone know any details behind this restriction? I have a number of unit tests which definitely violate this rule but seem to function properly, however. 回答1: I have to disagree with @Marko Popovic's assessment, and believe what he's

Interleaving EXPECT_CALL()s and calls to the mock functions

前提是你 提交于 2020-05-15 04:03:35
问题 The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined . In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions. Does anyone know any details behind this restriction? I have a number of unit tests which definitely violate this rule but seem to function properly, however. 回答1: I have to disagree with @Marko Popovic's assessment, and believe what he's

Interleaving EXPECT_CALL()s and calls to the mock functions

戏子无情 提交于 2020-05-15 04:03:25
问题 The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined . In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions. Does anyone know any details behind this restriction? I have a number of unit tests which definitely violate this rule but seem to function properly, however. 回答1: I have to disagree with @Marko Popovic's assessment, and believe what he's

google mock - how to say “function must be called ONCE with a certain parameter but ok to be called many times with different parameters”?

心不动则不痛 提交于 2020-05-13 05:57:25
问题 I need to detect that a given function has been called exactly ONCE with a certain set of arguments. EXPECT_CALL(Mock_Obj, func("abc")).Times(1) but it's ok for that function to be called with different arguments any number of times. How do I express that? 回答1: In Google Mock, later expectations override earlier ones (more details in the docs), so you can write this: EXPECT_CALL(Mock_Obj, func(_)).Times(AnyNumber()); EXPECT_CALL(Mock_Obj, func("abc")).Times(1); 回答2: Do like VladLosev said.

google mock - how to say “function must be called ONCE with a certain parameter but ok to be called many times with different parameters”?

若如初见. 提交于 2020-05-13 05:57:15
问题 I need to detect that a given function has been called exactly ONCE with a certain set of arguments. EXPECT_CALL(Mock_Obj, func("abc")).Times(1) but it's ok for that function to be called with different arguments any number of times. How do I express that? 回答1: In Google Mock, later expectations override earlier ones (more details in the docs), so you can write this: EXPECT_CALL(Mock_Obj, func(_)).Times(AnyNumber()); EXPECT_CALL(Mock_Obj, func("abc")).Times(1); 回答2: Do like VladLosev said.

google mock - how to say “function must be called ONCE with a certain parameter but ok to be called many times with different parameters”?

旧时模样 提交于 2020-05-13 05:57:07
问题 I need to detect that a given function has been called exactly ONCE with a certain set of arguments. EXPECT_CALL(Mock_Obj, func("abc")).Times(1) but it's ok for that function to be called with different arguments any number of times. How do I express that? 回答1: In Google Mock, later expectations override earlier ones (more details in the docs), so you can write this: EXPECT_CALL(Mock_Obj, func(_)).Times(AnyNumber()); EXPECT_CALL(Mock_Obj, func("abc")).Times(1); 回答2: Do like VladLosev said.

Compile-errors: “creating array with negative size ('-0x00000000000000001')”, “assignment of read-only location”

爱⌒轻易说出口 提交于 2020-01-25 05:31:11
问题 Hi I'm new to GoogleMock but not new to mocking (I've python experience). For a C-code based interface we want to use Googlemock. Up to compiling everything goes smoothly. No problems with defining the C-based code: mock-header-file #include "gmock/gmock.h" extern "C" { #include "interface/interfacetype.h" } struct HELPER { virtual ~HELPER() {} virtual int interface_func( ID_ENUM_TYPE id, MY_STRUCT_TYPE *params) = 0; }; struct INTERFACE_MOCK : public HELPER { MOCK_METHOD2( interface_func, int