如何编写单元测试来返回作为未来一部分的响应的状态代码?我在卡住之前走了这么远
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)));
});这与消息失败。
FAIL: test future Expected: <Closure: (Response) => dynamic>
Actual: <Instance of 'Response'>然后我试着
solo_test( "test response status", (){
http.get( "http://www.google.com").then( expectAsync0((response)=>expect( response.statusCode,200)));
});消息失败。
Test failed: Caught type '() => dynamic' is not a subtype of type '(dynamic) => dynamic' of 'f'.发布于 2013-12-10 09:35:58
似乎是这样的
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 )));
});
});
} https://stackoverflow.com/questions/20490349
复制相似问题