草庐IT

gmock-matchers

全部标签

c++ - 如何设置 GMock EXPECT_CALL 为模拟函数调用两个不同的函数

如何在“测试套件”中的测试函数中调用模拟函数时调用两个不同的函数?详细信息:模拟函数在测试函数中被调用两次。第一次调用时,它应该调用一个函数(测试套件中的本地函数),第二次调用时,它应该调用另一个函数(测试套件中的另一个本地函数)。那么,如何为上述需求设置EXPECT_Call为“Invoke”呢? 最佳答案 你应该使用WillOnce。像这样的(未经测试):structA{MOCK_METHOD0(foo,void());};classA_Test:public::testing::Test{Aa;voidbar1(){}void

c++ - GMock - 使用 ON_CALL 为重载方法返回默认值

我正在尝试为包含三个重载方法的类编写模拟,即:#include#includeusing::testing::_;using::testing::Return;using::testing::A;using::testing::ByRef;using::testing::Ref;using::testing::TypedEq;structFoo{intfooMethod(constint&intParam){return0;}intfooMethod(constfloat&floatParam){return0;}intfooMethod(conststd::string&string

Java正则表达式及Pattern与Matcher使用详解

文章目录一、正则表达式详解1、符号定义(1)基本书写符号(2)限定符(3)匹配字符集(4)分组构造(5)字符转义2、常用正则表达式举例3、Java中RegularExpressionValidator用正则表达式校验4、正则表达式匹配简单语法汇总二、Pattern类详解1、获取Pattern实例(1)实例2、组和捕获3、intflags()方法4、Stringpattern()方法5、String[]split(CharSequenceinput)方法6、String[]split(CharSequenceinput,intlimit)方法(1)实例7、Pattern.matches(Stri

android - 将 Mockito Matchers.any() 与 android.support.annotation.IntDef 自定义注释一起使用

我正在尝试编写一个Junit测试来验证是否调用了以下方法:publiclongexecuteRequest(@RequestCodes.Code.RequestAnnotationintrequestCode,ObjectrequestInformation,RequestListenerrequestListener){booleansuccess=false;...dostuff...returnsuccess?1L:-1L;}在测试中使用:Mockito.when(mockedRequest.executeRequest(Matchers.any(RequestCodes.Cod

android - 找不到 com.google.android.gms :strict-version-matcher-plugin:1. 1.0

无法解析配置“类路径”的所有文件。找不到com.google.android.gms:strict-version-matcher-plugin:1.1.0。在以下位置搜索:https://jcenter.bintray.com/com/google/android/gms/strict-version-matcher-plugin/1.1.0/strict-version-matcher-plugin-1.1.0.pomhttps://jcenter.bintray.com/com/google/android/gms/strict-version-matcher-plugin/1.

替换()vs.替换(...,matcher.quoteplacement)

你好:d简短问题:有什么区别Stringgeb=tf_datum.getText();Stringsep="";//sepisshortforseperatorgeb=geb.replaceAll("\\.",sep);geb=geb.replaceAll("\\,",sep);geb=geb.replaceAll("\\-",sep);geb=geb.replaceAll("\\",sep);`和Stringgeb=tf_datum.getText();Stringsep="";geb=geb.replaceAll("\\.",Matcher.quoteReplacement(sep));g

当使用Java常规表达模式.matcher()时,源不匹配正则匹配,但我的希望结果是,源匹配正则

当使用Java常规表达模式.matcher()时,源不匹配正则匹配。Stringsource="ONE.TWO"Stringregex="^ONE\\.TWO\\..*"importjava.util.regex.Pattern;publicclassTest{publicstaticvoidmain(String[]args){test();}publicstaticvoidtest(){TeststringDemo=newTest();stringDemo.testMatcher();}publicvoidtestMatcher(){Stringsource="ONE.TWO";Strin

c++ - Gmock - 匹配结构

如何为输入参数匹配union中元素的值,例如-如果我模拟具有以下签名的方法-structSomeStruct{intdata1;intdata2;};voidSomeMethod(SomeStructdata);我如何才能匹配调用此方法的mock,并在参数中使用正确的值? 最佳答案 在详细阅读了Googlemock文档之后,我解决了我在DefiningMatchers中记录的问题部分。(一个例子会很棒!)因此解决方案是使用MATCHER_P宏来定义自定义匹配器。所以对于匹配的SomeStruct.data1我定义了一个匹配器:MAT

c++ - 使用 GMock 验证析构函数调用

使用GMock,我如何验证类的析构函数是否被调用?除了wrapitinanotherclass,还有其他办法吗??明显的方法EXPECT_CALL(object,~classtype())会产生编译器错误(gmock无法生成名为gmock_~classtype的模拟方法)。 最佳答案 检查析构函数调用的简单方法:classMockFoo:publicFoo{...//Addthefollowingtwolinestothemockclass.MOCK_METHOD0(Die,void());virtual~MockFoo(){Die

c++ - 是否可以使用 Google Mock (gmock) 捕获参数?

我打算使用GoogleMock。我需要捕获对象引用,以便随后可以从该对象调用一些方法。GoogleMock有捕捉能力吗?如果没有,C++单元测试的其他选择是什么?一种选择是创建我自己的模拟类来捕获对象。我正在寻找类似于Java的EasyMock的东西.示例(非真实代码):Capturecapture;EXPECT_CALL(myInterface,access(capture));instanceUnderTest.setAccessPoint(myInterface);instanceUnderTest.run();MyObject&capturedObject=capture.ge