#include "gtest/gtest.h"
#include "mockcpp/mockcpp.hpp"
int add(int value1, int value2) {
return value1 + value2;
}
TEST(MOCK, mock_function_test)
{
MOCKER(add)
.stubs()
.will(returnValue(100));
int value = add(1, 2);
ASSERT_EQ(100, value);
}
执行结果:
[----------] 1 test from MOCK
[ RUN ] MOCK.mock_function_test
../test/src/mock/MockTest.cpp:16: Failure
Expected equality of these values:
100
value
Which is: 3
[ FAILED ] MOCK.mock_function_test (0 ms)
[----------] 1 test from MOCK (0 ms total)
工程是gtest+mockcpp linux版本: ubuntu 22.04 Linux openbmc 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
gcc版本: gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 c++标准: c++20
代码:
执行结果: [----------] 1 test from MOCK [ RUN ] MOCK.mock_function_test ../test/src/mock/MockTest.cpp:16: Failure Expected equality of these values: 100 value Which is: 3 [ FAILED ] MOCK.mock_function_test (0 ms) [----------] 1 test from MOCK (0 ms total)