googletest

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.

How to mock methods return object with deleted copy-ctor?

耗尽温柔 提交于 2020-05-12 12:09:06
问题 If an interface has a function to create an object with deleted copy-ctor, how to mock this function? Gmock seems to use the object's copy constructor internally. E.g. // The object with deleted copy-ctor and copy-assignment class TTest { public: TTest() = delete; TTest(const TTest&) = delete; TTest& operator=(const TTest&) = delete; TTest(TTest&&) = default; TTest& operator=(TTest&&) = default; explicit TTest(int) { } }; // My interface to mock class MyInterface { public: virtual

undefined reference to testing::internal::EqFailure in gtest

天涯浪子 提交于 2020-05-11 05:34:58
问题 I am trying to do a test for a function using GoogleTest an now it is not finding anymore the EqFailure thing : /usr/include/gtest/gtest.h:1337: undefined reference to `testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)' I am writing the test like this: test_file.cpp : #include <gtest/gtest.h> #include "tools/CMorphology.hpp" TEST(erode_Morph, crossKernel_Morph) { // initialize matrix to be eroded cv::Mat matrix =

undefined reference to testing::internal::EqFailure in gtest

核能气质少年 提交于 2020-05-11 05:33:37
问题 I am trying to do a test for a function using GoogleTest an now it is not finding anymore the EqFailure thing : /usr/include/gtest/gtest.h:1337: undefined reference to `testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)' I am writing the test like this: test_file.cpp : #include <gtest/gtest.h> #include "tools/CMorphology.hpp" TEST(erode_Morph, crossKernel_Morph) { // initialize matrix to be eroded cv::Mat matrix =

Disable exception handling while debugging c++ project using Google Test

不羁的心 提交于 2020-05-09 01:21:35
问题 I have my (native C++) DLL project and a corresponding test EXE project based on Google Test. While debugging my DLL via this EXE I have exceptions automatically handled by Google Test. So if my DLL throws an unhandled exception during debug, I expect to see error message from Visual Studio with debug session paused after the code caused exception. Instead, I have breakpoint triggered in gtest.cc. And if I disable --gtest_break_on_failure flag I will receive no breaks at all. I found no such

Visual Studio2019 使用Google Test(gtest)

六眼飞鱼酱① 提交于 2020-05-01 20:18:19
环境:Windows10 VS2019 刚开始接触gtest,搜了一大堆教程,但都是VS2017甚至是更老版本的,摸索了一圈还是不会用,后来发现VS2019中自带gtest(泪) 下面是我自己探索出的用法,如果有不对的地方希望朋友们走过路过帮忙纠正(感谢) 下面正文开始->查找到Google Test 创建一个新项目 设置项目配置 写一个简单的加法 测试程序 开始编译! 就是酱紫!本小菜鸡的初步探索完成!撒花撒花~ 感叹:VS2019也太方便了! 来源: oschina 链接: https://my.oschina.net/u/4368375/blog/4261203

gmock - how to mock function with noexcept specifier

谁都会走 提交于 2020-04-18 06:53:26
问题 I need to mock the following function: virtual void fun() noexcept = 0; Is it possible using gmock ? Gmock has the following macro: #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) but there is a comment: // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! Moreover I don't know how to use that macro (what the parameters tn and ct means) ? Edit The following mock: GMOCK_METHOD0_(, noexcept, ,fun, void()); compiles with gmock 1.7.0 but when I compile it using gmock 1.8.1 I get the