首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单元测试Http状态码

单元测试Http状态码
EN

Stack Overflow用户
提问于 2013-12-10 09:17:35
回答 1查看 1K关注 0票数 2

如何编写单元测试来返回作为未来一部分的响应的状态代码?我在卡住之前走了这么远

代码语言:javascript
复制
import 'package:http/http.dart' as http;

 test( "test future", (){
     Future<Response> future = http.get( "http://www.google.com");
      expect( future, completion( equals( ( Response e)=>(e.statusCode ), 200)));
});

这与消息失败。

代码语言:javascript
复制
FAIL: test future   Expected: <Closure: (Response) => dynamic>
    Actual: <Instance of 'Response'>

然后我试着

代码语言:javascript
复制
 solo_test( "test response status", (){
    http.get( "http://www.google.com").then( expectAsync0((response)=>expect( response.statusCode,200)));
  });

消息失败。

代码语言:javascript
复制
Test failed: Caught type '() => dynamic' is not a subtype of type '(dynamic) => dynamic' of 'f'.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-10 09:35:58

似乎是这样的

代码语言:javascript
复制
void main(List<String> args) {
   test( "test future", (){
     test( "test future", (){
       Future<http.Response> future = http.get( "http://www.google.com");
       expect(future.then((http.Response e) => e.statusCode), completion(equals( 200 )));
      });
   });
}   
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20490349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档