I'm trying dart and I'm writing a client on the server side :
new HttpClient().post(InternetAddress.LOOPBACK_IP_V4.host, 7474, '/path').then((HttpClientRequest request) {
request.headers.contentType = ContentType.JSON;
request.headers.add(HttpHeaders.ACCEPT, ContentType.JSON);
request.write(JSON.encode(jsonData));
return request.close();
}).then((HttpClientResponse response) {
response.transform(UTF8.decoder).listen((contents) {
_logger(contents);
// stuff
});
});
and I would like to mock the server response.
What is the best solution ?
- Create a server in my test class that will return the value I expect ?
- or mock the HttpClientResponse ?
Thanks for your help ! (code would be greatly appreciated ;D)
The http packages provides support for this.
See http://www.dartdocs.org/documentation/http/0.11.1+1/index.html#http/http-testing for examples.