- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如果匹配失败,Google mock 会打印如下消息:
test.cpp:112: EXPECT_CALL(mock_obj, foo( MyMatcher( bar ) ))...
Expected arg #0: is equal to [1,2; 3,4]
Actual: { 1 }
Expected: to be called once
Actual: never called - unsatisfied and active
使用自定义匹配器 MyMatcher 我可以定义一个描述字符串,用于在匹配失败时生成失败消息。但它只定义了消息的 Expected arg #0 部分。有什么方法可以自定义 Actual 的打印方式吗?
在我的例子中,我不能为 bar 的类重载 operator<< 因为它已经被第三方代码重载了,不在我的控制之下(这个库定义了 bar 和 operator<< 。
最佳答案
因为我不能能够定义operator
<<
对于我的 class
,谷歌测试有选项定义PrintTo
它的功能Teaching Google Test How to Print Your Values .谢谢RA链接。
A user can override this behavior for a class type Foo by defining an overload of PrintTo() in the namespace where Foo is defined. We give the user this option as sometimes defining a << operator for Foo is not desirable (e.g. the coding style may prevent doing it, or there is already a << operator but it doesn't do what the user wants).
void PrintTo(const Bar& value, ::std::ostream* os);
关于c++ - 谷歌模拟 : How to configure custom message to explain match failure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15349116/
我是一名优秀的程序员,十分优秀!