- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用 gtest
一段时间了,但最近想尝试一下 gmock
。我正在尝试使用返回值的方法模拟类,但也通过引用在输出参数中返回一些东西。这是我的小代码。
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace ::testing;
class AReal
{
public:
virtual bool foo(std::vector<int>& v) const = 0;
};
class AMock : public AReal
{
public:
MOCK_CONST_METHOD1(foo, bool(std::vector<int>&));
};
class B
{
public:
B(AReal* _a) : a(_a) {}
bool foo(std::vector<int>& v) const { return a->foo(v); }
private:
AReal* a;
};
class FooTest : public Test {};
TEST_F(FooTest,
DummyTestVector) {
AMock a;
B b(&a);
std::vector<int> exp = { 1, 2, 3 };
EXPECT_CALL(a, foo(_))
.Times(1)
.WillOnce(AllOf(SetArgReferee<0>(exp), Return(true)));
std::vector<int> load;
EXPECT_TRUE(a.foo(load));
EXPECT_EQ(exp, load);
}
int main(int argc, char** argv) {
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
但是,这段代码给我这个错误。
$ g++ -Wall -Wextra -std=c++14 -I. -o test test.cpp gmock-gtest-all.cc -lpthread
test.cpp: In member function ‘virtual void FooTest_DummyTestVector_Test::TestBody()’:
test.cpp:40:61: error: no matching function for call to ‘testing::internal::TypedExpectation<bool(std::vector<int>&)>::WillOnce(testing::internal::AllOfResult2<testing::SetArgRefereeActionP<0, std::vector<int> >, testing::internal::ReturnAction<bool> >::type)’
.WillOnce(AllOf(SetArgReferee<0>(exp), Return(true)));
^
In file included from test.cpp:2:0:
gmock/gmock.h:10172:21: note: candidate: testing::internal::TypedExpectation<F>& testing::internal::TypedExpectation<F>::WillOnce(const testing::Action<F>&) [with F = bool(std::vector<int>&)]
TypedExpectation& WillOnce(const Action<F>& action) {
^
gmock/gmock.h:10172:21: note: no known conversion for argument 1 from ‘testing::internal::AllOfResult2<testing::SetArgRefereeActionP<0, std::vector<int> >, testing::internal::ReturnAction<bool> >::type {aka testing::internal::BothOfMatcher<testing::SetArgRefereeActionP<0, std::vector<int> >, testing::internal::ReturnAction<bool> >}’ to ‘const testing::Action<bool(std::vector<int>&)>&’
如果我不使用 AllOf
而是只指定一个操作,SetArgReferee
或 Return
,一切正常。 AllOf
的使用会导致此类错误。我在这里找到了 AllOf
gmock multiple in-out parameters SetArgReferee基本上我的代码与答案相同。
最佳答案
在尝试了整个下午之后,我发现这只是我的愚蠢。我一直以某种方式认为 AllOf == DoAll
。才意识到这一点。
关于googletest - Googlemock - WillOnce 中的多个操作导致构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35672214/
gtest 有没有办法让内联/测试用例甚至测试超时。 例如,我想做类似的事情: EXPECT_TIMEOUT(5 秒,myFunction()); 我从 2010 年 12 月 9 日发现这个问题 g
我正在尝试googletest。 以前,我一直在使用Boost测试,并且一直在使用宏BOOST_AUTO_TEST_SUITE将测试分组到Testsuite中。 这使junit报告更具可读性。 我在g
我的 googletest 具有以下结构: void check(Arg a1, Arg a2) { EXPECT_TRUE(a1 == a2); } TEST(s, t) { a1 =
我有 2 种方法的类(class) class A { void Fun() { if(FunRet()>0){///} else {///} } int FunRet()
我正在使用 gtest 编写一个类型参数化的测试装置,我看到了 not declared in this scope当我尝试使用夹具类的成员时出现编译器错误。 当我不使用类型参数化装置时,我可以很好地
我在gtest中使用值参数化测试。例如,如果我写 INSTANTIATE_TEST_CASE_P(InstantiationName, FooTest,
我有一个用C ++编写的程序,其中一些子文件夹包含链接的库。有一个顶级SConscript,它在子文件夹/库中调用SConscript文件。 在库cpp中,有一个GTest: TEST(X, just
为了对某些代码进行 BDD 风格的测试,我有一组测试,我想针对多个场景执行这些测试。我已经在 C# 中使用 NUnit & NSubstitute 多次这样做了,但是我正在努力使用 GoogleTes
我正在尝试为向量编写测试。 对于 STL 容器,我尝试过: EXPECT_THAT(float_vec1, ElementsAreArray(float_vec2)); 但是我需要插入一个边距。 有没
使用 Google Test 1.6(Windows 7、Visual Studio C++)。如何关闭给定的测试? (又名如何阻止测试运行)。除了注释掉整个测试之外,我还能做些什么吗? 最佳答案 d
如果一个测试有多个EXPECT_*语句 TEST_F(TestClass, ServerTest) { // Start server server_.start(); usl
当我编写测试夹具来测试一些 C 代码时,我使用相同的设置: https://github.com/google/googletest/blob/master/googletest/docs/prime
给定一个包含数千个测试的大型项目,其中一些测试需要几分钟才能完成。按顺序执行时,整套测试需要一个多小时才能完成。通过并行执行测试可以减少测试时间。 据我所知,没有办法直接从 googletest/mo
我在 googletest 中运行一些单元测试。我期望对模拟函数的某些调用 (EXPECT_CALL(*rtosMock, xQueueGenericSend( arg , _, _, _)).Tim
我刚刚开始学习 googletesting,并且正在使用它。我想使用参数化测试来检查类的函数成员返回的值是否是它应该的值。我已经声明了一个名为“myClass”的类,在其中我使用构造函数设置了一个变量
我有一个抽象基类,它具有处理线程生命周期(启动、停止、加入)的逻辑。线程中执行的工作依赖于实例化的派生类,派生类有几个。 基类如下所示: class Base { public: Base(i
是什么原因,为什么GoogleTest对参数计数使用引用? testing::InitGoogleTest(&argc, argv); (我的意思是:据我了解,这是一个输入参数,没有任何区别是否提
我正在为遗留代码创建测试,想知道是否可以像这样检查类的成员变量的值(我知道我下面的代码非常糟糕,糟糕的例子:/。希望只是请关注关于问题): class Animal { public: RESU
这是我的测试夹具:https://github.com/patrykbajos/ZinotEngine/blob/master/src/tests/core/MapResMgrTest.cpp .此可
我想知道,是否有可能检查失败的 ASSERT 或 EXPECT 语句,这些语句发生在被调用函数内部并且独立于任何其他或先前的失败 ASSERT/EXPECT 语句。基本上: void subcheck
我是一名优秀的程序员,十分优秀!