- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
my_inet.cpp
文件中创建了一个外部套接字 api 的模拟。mock.h
文件中。server.cpp
文件中使用我创建的 my_inet
套接字 api。gtest.cpp
编写。我想通过 exit(1)
成功执行死亡案例,但 GMock 说“无法死亡”。
为什么?
gtest.cpp
TEST(MyTest, SocketConnectionFail)
{
MockMyTCPAPI obj_myTCP;
Server obj_server( &obj_myTCP );
EXPECT_DEATH( obj_server.InitializeSocket(), "No socket connection!");
}
服务器.cpp
int Server::InitializeSocket()
{
if( ret_val_socket == -1 )
{
ret_val_socket = myTCPAPI->socket( PF_INET, SOCK_STREAM, 0 );
if( ret_val_socket == -1 )
{
printf( "\nNo socket connection!" );
exit(1);
}
return ret_val_socket;
}
else
{
printf( "Warning! Attempting to create socket again. %d" , ret_val_socket);
return 2;
}
return 0;
}
my_inet.cpp
int MyTCPAPI::socket( int arg1, int arg2, int arg3 )
{
return -1;
}
输出:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MyTest
[ RUN ] MyTest.SocketConnectionFail
[WARNING] /usr/src/gtest/src/gtest-death-test.cc:825:: Death tests use fork(), which is unsafe particularly in a threaded context. For this test, Google Test couldn't detect the number of threads.
GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: socket(1, 0, 0)
Returns: 0
Stack trace:
/home/anisha/Documents/office/tdd/tcp/server/gtest.cpp:56: Failure
Death test: obj_server.InitializeSocket()
Result: failed to die.
Error msg:
[ DEATH ]
[ FAILED ] MyTest.SocketConnectionFail (3 ms)
[----------] 1 test from MyTest (3 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (3 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] MyTest.SocketConnectionFail
1 FAILED TEST
最佳答案
输出解释了这个问题:
GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: socket(1, 0, 0)
Returns: 0
这意味着 myTCPAPI->socket(PF_INET, SOCK_STREAM, 0)
返回 0,而不是 -1。
由于 MockMyTCPAPI obj_myTCP
是模拟对象(不是 MyTCPAPI
),它不会运行 MyTCPAPI::socket()
。您需要指定它的返回值。类似以下内容应该有所帮助:
EXPECT_CALL(obj_myTCP, socket(_, _, _))
.WillRepeatedly(Return(-1));
或者在测试中使用 MyTCPAPI
而不是 MockMyTCPAPI
。
关于c++ - 带有 GMock 的 EXPECT_DEATH - 未能死亡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55375912/
我很快就会明白,我不是 Git 甚至 Gitkraken 的高手。因此,我只有一个修补程序、一个主分支和一个功能分支。我在修补程序、提交、推送和 merge 到 master 中进行更改(然后我也推送
我刚开始使用 stub 请求来测试对 iOS 的外部 API 的异步调用。我目前被以下代码困住了,我无法弄清楚什么不起作用。 我想要实现的非常简单的事情是,如果我从网站收到 200 响应,我将 Vie
设置: 一个 JPA ReviewRepository延长 CrudRepository 我的测试使用切片测试注释 @DataJpaTest 我的测试@Autowired ReviewReposito
我尝试通过logstash将csv文件vrom filebeat摄取到hdfs中。 Filebeat 成功将其转移到 logstash,因为我使用 stdout{codec=>rubydebug} 并
我看到很多教程解释了如何在 Tensorflow 的 Bazel WORKSPACE 中构建项目(例如 this one)。但我似乎无法找到一种方法来构建我自己的项目并将 tensorflow 作为依
我正在运行 Ubuntu 10.04 并且最初安装了 ruby 1.9.1(来自源代码)。我刚刚决定试用 ruby 1.9.2 和 rails 3,现在似乎是使用 rvm 处理多个 ruby
我有一个应用程序从后端接收支持的语言环境列表作为以下响应: {locales: [{code: 'enUS'}, {code: 'deDE'}, {code: 'arAR'}]} 我想使用 date-
我是一名优秀的程序员,十分优秀!