我必须使用什么样的测试
What kind of Testing I have to use?
我写了一些代码,可以随时侦听Web服务。根据结果,我将向 Web 服务发送一些请求,并根据响应发送进一步的请求。如果一切正常,我将开始监听Web服务,直到发生一些中断。
遵循伪代码(种类)
class listner
{
string sendReq(Request)
{
curl_easy_perform();
return responseString;
}
connectWebServive()
{
curl = curl_easy_init();// curl member variable CURL *curl;
while(true)
{
String res = listener(Request1)
if(res == “some thing”)
{
String res = listener(Request2)
}
else
{
String res = listener(Request3)
}
while(true)
{
String res = listener(request4)
if(somethingWrong)
{
break;
}
}
}
}
}
如何测试此代码?我应该使用分支覆盖率测试还是代码覆盖率测试?
谢谢
分支和行/语句覆盖率是不同的指标,可帮助了解正在测试的内容。在任何一种情况下,这都将取决于作为 API 响应的数据或事件,因此对覆盖率指标的任何解释都意味着,如果您希望执行准确的分析,则需要为所有分支创建测试。
为了提高可读性,我建议不要使用嵌套的while循环。应该有一个等待响应的侦听器循环。该循环的内部结构包含处理逻辑和 if-then-else 树。应该有一个默认的起始请求(入口点),然后逻辑应该检查输入以决定下一个请求是什么。
current_request = construct_original_request()
while(true)
{
response = do_request(current_request) // make a blocking call in thread
if(response like 'condition A')
{
// do A logic, if any
current_request = construct_B_request()... // then set up next request
} else if(response like 'condition B')
{
// do B logic if any
current_request = construct_C_request()... // then set up next request
} else
{
current_request = construct_original_request() // back to square one
}
wait(1) // let the thread/processor sleep for a non-zero amount of time
}
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 数据成员SFINAE的C++17测试:gcc vs clang
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么二进制搜索在我的测试中不起作用
- 从父数组测试用例构造二叉树失败
- 试图对缓存进行跨步测试,但程序并没有结束
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- OpenGL在启用深度测试时不会丢弃我的碎片
- 为测试目标创建具有不同源文件夹的文件
- 在子目录中使用target_sources()命令时用于单元测试(qtest)的项目结构
- VC++本机单元测试,找不到调试符号
- 换位表导致测试失败(但在游戏中运行良好)
- 用于交叉编译和CMake的预处理器宏的单元测试
- 谷歌测试中的期望值存储在哪里
- 返回的指向C++对象的链接是什么样的
- 如何在for循环中包含两个索引值的测试条件
- 在cygwin中测试新的boost安装时出现cpp错误
- 我必须使用什么样的测试