【问题标题】:What kind of Testing I have to use?我必须使用什么样的测试?
【发布时间】:2017-01-10 17:18:22
【问题描述】:

我编写了一些代码,可以随时监听 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;
          }                  
       }
    }
}
}

如何测试此代码?我应该使用分支覆盖率还是代码覆盖率测试?

谢谢

【问题讨论】:

    标签: c++ testing boost


    【解决方案1】:

    分支和行/语句覆盖率是不同的指标,可帮助了解哪些内容正在接受测试。无论哪种情况,这都取决于作为 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
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-12
      • 2012-01-22
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      相关资源
      最近更新 更多