sinojelly / mockcpp

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

seems can not work with gtest #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. hg clone https://mockcpp-samples.googlecode.com/hg/ mockcpp-samples
2. add CMakeLists.txt in mockcpp-samples
   Project(Test)

SET(TOOLS_DIR ${CMAKE_SOURCE_DIR}/../tools)

INCLUDE_DIRECTORIES(${TOOLS_DIR}/gtest/include)
INCLUDE_DIRECTORIES(${TOOLS_DIR}/mockcpp/include)
INCLUDE_DIRECTORIES(${TOOLS_DIR}/3rdparty)
LINK_DIRECTORIES(${TOOLS_DIR}/gtest/lib ${TOOLS_DIR}/mockcpp/lib)

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)

ADD_EXECUTABLE(Test ${CMAKE_SOURCE_DIR}/test/footest.cpp 
${CMAKE_SOURCE_DIR}/src/foo.cpp)

TARGET_LINK_LIBRARIES(Test libgtest_main.a libgtest.a pthread 
libmockcpp4gtest.a)

3. compile mockcpp with cmake -DMOCKCPP_XUNIT=gtest 
-DMOCKCPP_XUNIT_HOME=/home/james/ExtDir/share/MockFramework/mockcpp-samples/tool
s/gtest 
-DCMAKE_INSTALL_PREFIX=/home/james/ExtDir/share/MockFramework/mockcpp/install ..
4. make install
4. cp install/lib/libmockcpp.a 
/home/james/ExtDir/share/MockFramework/mockcpp-samples/tools/mockpp/lib/libmockc
pp4gtest.a
5. cp -r install/include 
/home/james/ExtDir/share/MockFramework/mockcpp-samples/tools/mockpp/
6. compile mockcpp-samples
7. run test
result is :
[----------] 2 tests from TestApiHook
[ RUN      ] TestApiHook.test_api_hook_ok
[       OK ] TestApiHook.test_api_hook_ok (0 ms)
[ RUN      ] TestApiHook.test_api_hook_fail
/home/james/ExtDir/share/MockFramework/mockcpp-samples/gtest-samples/../tools/mo
ckcpp/include/mockcpp/ChainableMockMethod.h:69: Failure

=====================================
Unexpected invocation: the invocation cannot be found in allowed invoking list.
Invoked: add((int)0x1/1, (int)0x2/2)
Allowed: 
method(add)
     .expects(once())
     .invoked(0)
     .with(eq((int)0x2/2), eq((int)0x3/3))
     .will(returnValue((int)0x14/20));

=====================================

terminate called after throwing an instance of 'mockcpp::AssertionFailedError'
  what():  failed due to mockcpp exception
abandoned

What is the expected output? What do you see instead?
the result should be gtest's statistics, but the test program is exit, if there 
are some other test cases, maybe won't get invoked.

What version of the product are you using? On what operating system?
mockcpp-2.5-20110326.rar 
Linux james-VirtualBox 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 
2010 i686 GNU/Linux 

Please provide any additional information below.

Original issue reported on code.google.com by col...@gmail.com on 3 Jun 2011 at 10:13

GoogleCodeExporter commented 9 years ago
because mockcpp report failures by exception, but gtest doesn't caught it.
now, you can use mockcpp with gtest, but if some test failure, the other tests 
may not run.
I suggest you use testngpp instead of gtest.
http://code.google.com/p/test-ng-pp
or use cpp-ut-project integrated solution:
http://code.google.com/p/cpp-ut-project
see also:
http://code.google.com/p/cpp-project/

Original comment by sinoje...@gmail.com on 4 Jun 2011 at 3:01

GoogleCodeExporter commented 9 years ago
mockcpp maybe can not works well with gtest shipped with mockcpp-samples, 
however, it do works with gtest 1.6.0. 

I think this can be marked as solved.

the result is as follow:

Running main() from gtest_main.cc
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from TestApiHook
[ RUN      ] TestApiHook.test_api_hook_ok
[       OK ] TestApiHook.test_api_hook_ok (1 ms)
[ RUN      ] TestApiHook.test_api_hook_fail
/home/james/ExtDir/share/MockFramework/mockcpp-samples/gtest-samples/../tools/mo
ckcpp/include/mockcpp/ChainableMockMethod.h:69: Failure

=====================================
Unexpected invocation: the invocation cannot be found in allowed invoking list.
Invoked: add((int)0x1/1, (int)0x2/2)
Allowed: 
method(add)
     .expects(once())
     .invoked(0)
     .with(eq((int)0x2/2), eq((int)0x3/3))
     .will(returnValue((int)0x14/20));

=====================================

unknown file: Failure
C++ exception with description "failed due to mockcpp exception" thrown in the 
test body.
[  FAILED  ] TestApiHook.test_api_hook_fail (0 ms)
[----------] 2 tests from TestApiHook (1 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (1 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestApiHook.test_api_hook_fail

 1 FAILED TEST

Original comment by col...@gmail.com on 7 Jun 2011 at 1:34

GoogleCodeExporter commented 9 years ago

Original comment by sinoje...@gmail.com on 2 Oct 2011 at 2:40