sinojelly / mockcpp

Two C/C++ testing tools, mockcpp and testngpp.
Apache License 2.0
66 stars 39 forks source link

stubs() does not take effect #33

Open tangshp opened 2 years ago

tangshp commented 2 years ago

1、code static int add(int left, int right) { return left + right; }

TEST(ft_test, demo) { GlobalMockObject::reset(); MOCKER(add).stubs().with(any()).will(returnValue(300)); EXPECT_EQ(300, add(1, 4)); }

2、test result [ RUN ] ft_test.demo /home/tangshp/Code_ws/googleTest_mockcpp/test/ft_test.cpp:13: Failure Expected equality of these values: 300 add(1, 4) Which is: 5 [ FAILED ] ft_test.demo (0 ms) [----------] 1 test from ft_test (0 ms total)

3、googletest+mockcpp mockcpp-build-step: ➜ build xunit_home=/usr/local ➜ build cmake -DMOCKCPP_XUNIT=gtest -DMOCKCPP_XUNIT_HOME=$xunit_home -DCMAKE_INSTALL_PREFIX=/usr/local .. ➜ build sudo make && make install

sinojelly commented 2 years ago

Test passed. I use the project here: https://gitee.com/sinojelly/gtest-with-mockcpp IDE: CLion Compiler:MinGW.

image